【问题标题】:SharePoint REST Query expand Self Referenced ColumnSharePoint REST 查询展开自引用列
【发布时间】:2014-03-18 04:28:09
【问题描述】:

我有两个列表。公司和员工。我在员工列表中有一个名为“公司”的查找列,它指向员工的 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 的查找列,并将其指向员工 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

但是没有任何效果。如何在同一个列表中使用展开?

【问题讨论】:

    标签: rest sharepoint


    【解决方案1】:

    以下 REST 端点

    /_api/web/lists/getbytitle('Employee')/items?$select=Title,Company/Title,Manager/Title&$expand=Company/Id,Manager/Id 
    

    返回Employee TitleCompany TitleManager 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));
        }
    }); 
    

    【讨论】:

      猜你喜欢
      • 2017-08-03
      • 2014-06-13
      • 1970-01-01
      • 2018-06-12
      • 2019-07-07
      • 1970-01-01
      • 2014-05-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多