我有两个清单。公司和员工。我有一个名为" company"在员工列表中,该列表指向员工的ID。
在我的REST查询中,我可以非常轻松地扩展公司的标题
http://abhi-sharepoint.abhishek.com/sites/dev/_api/web/lists/getbytitle('Employee')/items?$select=ID,Title,Company/Title&$expand=Company/Id&$filter=Company/Id%20eq%20%2714%27
非常好!
现在,我将另一个查找列添加到名为Manager的Employee List中,并将其指向employee id
现在我如何将ManagerId扩展为经理标题?
我试过
http://abhi-sharepoint.abhishek.com/sites/dev/_api/web/lists/getbytitle('Employee2')/items?$select=ID,Title,Employee2/Title,Company/Title&$expand=Company/Id&$expand=Manager/Id&$filter=Company/Id%20eq%20%2714%27
我也试过
http://abhi-sharepoint.abhishek.com/sites/dev/_api/web/lists/getbytitle('Employee2')/items?$select=ID,Title,Employee2/Title,Company/Title&$expand=Company/Id&$expand=Employee2/Id&$filter=Company/Id%20eq%20%2714%27
但没有任何作用。如何在同一列表中使用展开?
答案 0 :(得分:5)
以下REST端点
/_api/web/lists/getbytitle('Employee')/items?$select=Title,Company/Title,Manager/Title&$expand=Company/Id,Manager/Id
返回Employee Title
,Company Title
和Manager Title
,
其中Manager
字段是同一列表的Lookup
示例:
var query = "/_api/web/lists/getbytitle('Employee')/items?$select=Title,Company/Title,Manager/Title&$expand=Company/Id,Manager/Id";
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + query,
type: "GET",
headers: { "ACCEPT": "application/json;odata=verbose" },
success: function(data){
$.each(data.d.results, function(idx,item){
console.log(item.Title); //Employee Title
console.log(item.Company.Title); //Company Title
console.log(item.Manager.Title); //Manager Title
});
},
error: function(data){
console.log(JSON.stringify(data));
}
});