如何在SharePoint REST API中使用$ top获取匹配项计数? [英] How to get matched items count with $top in SharePoint REST API?
问题描述
/_ api/web/lists/getbytitle(listtitle)/getItems . SharePoint GET Rest API具有URL长度限制.因此,我们使用POST API来获取物品.
I am using SharePoint REST API. I am using post API to get the items /_api/web/lists/getbytitle(listtitle)/getItems
.
SharePoint GET Rest API has URL length limitation. Therefore we are using POST API to get the items.
我们有6万个商品的列表,阈值限制为70k.我们将在CAML查询中应用各种AND和OR操作,并使用$ top子句仅检索前200个项目.它工作正常,并给出了预期的结果.
We have list of 60k items with threshold limit of 70k. We are applying various AND and OR operations in CAML query and retrieving only first 200 items using $top clause. It is working fine and giving expected results.
在$ top = 200的情况下,使用data.d.results.length在ajax调用的成功方法中将结果的长度获取为200. CAML查询的匹配项为40k.如果不应用$ top,则data.d.results.length等于40k.当我们使用$ top = 200个项目时,我们希望此计数为(40k).
With $top=200, getting length of result as 200 in ajax call's success method using data.d.results.length. Matching items of CAML query is 40k. If we do not apply $top, data.d.results.length is equal to 40k. We want this count(40k) when we use $top=200 items. Is there any way to do this?
推荐答案
由于OOB不支持rest选项来获取总计数
As there is no OOB support for rest option to get total count with
top.top.您可以使用以下解决方法通过汇总函数获取总数.
SP.List list = ctx.Web.Lists.GetByTitle("Sales Order Details"); //STDEV string stdDev = "<View><ViewFields><FieldRef Name=\"OrderID\"/></ViewFields><RowLimit>1</RowLimit><Aggregations><FieldRef Name=\"OrderID\" Type=\"STDEV\" /></Aggregations></View>"; //VAR string strVar = "<View><ViewFields><FieldRef Name=\"OrderID\"/></ViewFields><RowLimit>1</RowLimit><Aggregations><FieldRef Name=\"OrderID\" Type=\"VAR\" /><FieldRef Name=\"OrderDate\" Type=\"COUNT\" /></Aggregations></View>"; SP.ClientResult<string> varView = list.RenderListData(strVar); SP.ClientResult<string> stdDevView = list.RenderListData(stdDev); ctx.ExecuteQuery();
strVar:: { "Row" : [{ "ID": "1", "PermMask": "0x7fffffffffffffff", "FSObjType": "0", "OrderID": "10,248", "OrderID.": "10248.0000000000", "<strong>OrderID.VAR</strong>": "31,148.024883361", "<strong>OrderDate.COUNT</strong>": "1599" } ],"FirstRow" : 1, "LastRow" : 1 ,"FilterLink" : "?" ,"ForceNoHierarchy" : "1" ,"HierarchyHasIndention" : ""}
这是供您参考的主题.
Lee
这篇关于如何在SharePoint REST API中使用$ top获取匹配项计数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!