我正在尝试从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) {
}
});
Run Code Online (Sandbox Code Playgroud)
在我的联系人列表中,我正在尝试检索以字符串开头或在其中包含字符串的项目的标题和ID,例如,这是某人的姓名.
我也尝试过substringof:
"/_api/lists/getByTitle('Contacts')/items?$select=Title,Id&$substringof(" + request.term + ",'Title') eq true"
Run Code Online (Sandbox Code Playgroud)
这也提供了相同的结果.
它为我提供了列表中的所有列表项,并且未应用过滤.我在看这里之后构建了Url for the Rest 使用SharePoint 2013 REST服务进行编程 就像在那里给出的Schema一样,我认为Url看起来不错,但似乎不是这样:)
编辑:
$filter在OData Uri约定中应用类似的方法给出了以下错误:
{"error":{"code":"-1, Microsoft.SharePoint.SPException","message":{"lang":"en-US","value":"The query is not valid."}}}
Run Code Online (Sandbox Code Playgroud)
尝试使用以下查询字符串:
_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
Run Code Online (Sandbox Code Playgroud)