我正在尝试过滤休息通话的结果。
$.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"
这也提供了相同的结果。
它为我提供了列表中的所有列表项,并且不应用任何过滤。 我在查看此处后为其余部分构建了 Url Programming using the SharePoint 2013 REST service 就像那里给出的架构一样,我认为网址看起来不错,但看起来并非如此:)
编辑:
像 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
_api/lists/getByTitle('Contacts')/items?$select=Title,Id&$filter=substringof('m',Title) eq true
最佳答案
当我删除“eq true”时,我已经设法让 substringof 的过滤器返回正确的结果。
使用您的查询字符串之一,它应该像这样工作:
_api/lists/getByTitle('Contacts')/items?$select=Title,Id&$filter=substringof('m',Title)
我没有检查任何其他函数,但至少,startswith 函数也会发生同样的情况。
关于rest - OData substringof 或startswith 返回所有项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16100697/