Mar*_*ark 8 rest jquery odata sharepoint-2013
我正在尝试从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)
小智 15
当我删除"eq true"时,我设法使用substringof获取过滤器返回正确的结果.
使用您的一个查询字符串,它应该像这样工作:
_api/lists/getByTitle('Contacts')/items?$select=Title,Id&$filter=substringof('m',Title)
Run Code Online (Sandbox Code Playgroud)
我没有检查任何其他功能,但至少,startwith功能也是如此.
小智 6
对于任何看过这个问题的人,我都可以报告
/_api/web/lists/GetByTitle('Applications')/items?$filter=startswith(Title,'1AAJ')
Run Code Online (Sandbox Code Playgroud)
我在为我工作.