3

REST API を使用して SharePoint リストの個別の列データを取得する方法は? ループせずにそれを達成する方法はありますか?

ありがとう!

4

2 に答える 2

7

Use OData query operations in SharePoint REST requestsによると、このような操作grouping はサポートされていません。

解決策は、JSON の結果が SharePoint REST サービスから返されたにグループ化を適用することです。

jQueryを使用して配列から個別の値を取得する方法

function groupBy(items,propertyName)
{
    var result = [];
    $.each(items, function(index, item) {
       if ($.inArray(item[propertyName], result)==-1) {
          result.push(item[propertyName]);
       }
    });
    return result;
}


var catalog = { products: [
   { category: "Food & Dining"},
   { category: "Techonology"},
   { category: "Retail & Apparel"},
   { category: "Retail & Apparel"}
]};

var categoryNames = groupBy(catalog.products, 'category'); //get distinct categories
console.log(categoryNames);

JSFiddle

SharePoint REST API を介してリスト アイテムを取得するために、次の関数が使用されているとします。

function getListItems(url, listname, query, complete, failure) {
    $.ajax({
        url: url + "/_api/web/lists/getbytitle('" + listname + "')/items" + query,
        method: "GET",
        headers: { "Accept": "application/json; odata=verbose" },
        success: function (data) {
            complete(data.d); 
        },
        error: function (data) {
            failure(data);
        }
    });
}

次に、次の例は、個別のタスク名を出力する方法を示しています。

getListItems('https://tenant.sharepoint.com/project','Tasks','?select=Title',
    function(items){    
       var taskNames = groupBy(items,'Title');
       console.log(taskNames);
    },
    function(error){
       console.log(JSON.stringify(error));
    }
);
于 2014-09-09T13:50:56.613 に答える
0

私が理解していることから、あなたは http:///_vti_bin/Lists.asmx について話していると思います。

はい、単純な SQL を使用してデータをクエリできるはずです - Distinct を選択してください...

ユーザー Web サービスにも同じ概念を使用しています。ただし、それはあなたにとっての単なるリードです。

参照: http://msdn.microsoft.com/en-us/library/office/ms429658(v=office.14).aspx

于 2014-09-09T12:41:51.660 に答える