【发布时间】:2013-04-12 14:46:03
【问题描述】:
我正在尝试过滤来自 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 就像那里给出的架构一样,我认为 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
_api/lists/getByTitle('Contacts')/items?$select=Title,Id&$filter=substringof('m',Title) eq true
【问题讨论】:
标签: rest jquery odata sharepoint-2013