微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

rest – OData substringof或startswith返回所有项目

我正在尝试从Rest Call中过滤我的结果.
$.ajax({
    type: "GET",headers: {
        "Accept": "application/json;odata=verbose"
    },dataType: "JSON",url: _spPageContextInfo.webServerRelativeUrl + "/_api/lists/getByTitle('Contacts')/items?$select=Title,Id&$startswith('Title','" + request.term + "') eq true",success: function (data) {
    },error: function (ex) {
    }
});

在我的联系人列表中,我正在尝试检索以字符串开头或在其中包含字符串的项目的标题和ID,这里例如它是某人的名字.

我也尝试过substringof:

"/_api/lists/getByTitle('Contacts')/items?$select=Title,Id&$substringof(" + request.term + ",'Title') eq true"

这也提供了相同的结果.

它为我提供了列表中的所有列表项,并且未应用过滤.
在看完Programming using the SharePoint 2013 REST service之后,我为其他人建立了Url
就像在那里给出的Schema一样,我认为Url看起来不错,但似乎不是这样:)

编辑:

在OData Uri约定中应用$filter会给我以下错误

{"error":{"code":"-1,Microsoft.SharePoint.SPException","message":{"lang":"en-US","value":"The query is not valid."}}}

尝试使用以下查询字符串:

_api/lists/getByTitle('Contacts')/items?$select=Title,Id&$filter=substringof(m,'Title') eq true

_api/lists/getByTitle('Contacts')/items?$select=Title,Id&$filter=substringof('m',Title) eq true

解决方法

当我删除“eq true”时,我设法使用substringof过滤器返回正确的结果.

使用您的一个查询字符串,它应该像这样工作:

_api/lists/getByTitle('Contacts')/items?$select=Title,Title)

我还没有检查过任何其他函数,但至少在startswith函数中也是这样.

原文地址:https://www.jb51.cc/jquery/178007.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐