[英]Using $skip with the SharePoint 2013 REST API
Forgive me, I'm very new to using REST. 原谅我,我对使用REST非常新。
Currently I'm using SP2013 Odata (_api/web/lists/getbytitle('<list_name>')/items?)
to get the contents of a list. 目前我正在使用SP2013 Odata
(_api/web/lists/getbytitle('<list_name>')/items?)
来获取列表的内容。 The list has 199 items in it so I need to call it twice and each time ask for a different set of items. 该列表中有199个项目,所以我需要调用它两次,每次都要求一组不同的项目。 I figured I could do this by calling:
我想我可以通过调用:
_api/web/lists/getbytitle('<list_name>')/items?$skip=100&$top=100
each time changing however many I need to skip. 每次改变,但我需要跳过很多。 The problem is this only ever returns the first 100 items.
问题是这只返回前100个项目。 Is there something I'm doing wrong or is
$skip
broken in the OData service? 有什么我做错了或者在OData服务中
$skip
了吗?
Is there a better way to iterate through REST calls, assuming this way doesn't work or isn't practical? 有没有更好的方法来迭代REST调用,假设这种方式不起作用或不实用?
I'm using the JSon protocol with the Accept
Header equaling application/json;odata=verbose
我正在使用JSon协议和
Accept
Header equaling application/json;odata=verbose
I suppose the $top=100
isn't really necessary 我认为
$top=100
并不是必需的
Edit: I've looked it up more and, I'm not entirely sure of the terms here, but using $skip
works fine if you're using the method introduced with SharePoint 2010, ie, _vti_bin/ListData.svc/<list_name>?$skip=100
编辑:我已经查了更多,我不完全确定这里的条款,但如果你使用SharePoint 2010引入的方法,使用
$skip
工作正常,即_vti_bin/ListData.svc/<list_name>?$skip=100
Actually, funny enough, the old way doesn't set a 100 item limit on returns. 实际上,有趣的是,旧的方式没有设置100项回报限制。 So skip isn't even necessary.
所以跳过甚至没有必要。 But, if you'd like to only return a certain segment of data, you'd have to do something like:
但是,如果您只想返回某一段数据,则必须执行以下操作:
_vti_bin/ListData.svc/<list_name>?$skip=x&$top=(x+y)
where each time through the loop you would have something like x+=y
每次通过循环,你会有像
x+=y
东西
You can either use the old method which I described above, or check out my answer below for an explanation of how to do this using SP2013 OData 您可以使用我上面描述的旧方法,或者查看下面的答案,了解如何使用SP2013 OData执行此操作
Alright, I've figured it out. 好吧,我已经明白了。
$skip
isn't a command which is meant to be used at the items?
$skip
不是一个用于items?
level. 水平。 It works only at the
lists?
它只适用于
lists?
level. 水平。 But, there's a way to do this, actually much easier than what I wanted to do.
但是,有一种方法可以做到这一点,实际上比我想做的容易得多。
If you just want all the data 如果您只想要所有数据
In the returned data, assuming the list you are calling holds more than 100 items, there will be a __next
at d/__next
(assuming you are using json). 在返回的数据中,假设您正在调用的列表包含超过100个项目,则下一个
d/__next
将有一个__next
(假设您使用的是json)。 This __next
(it is a double underscorce, keep that in mind. I had a few problems at first because I was trying to get d/_next
which never returned anything) is the right URL to get the next set of items. 这个
__next
(这是一个双重的问题,记住这一点。我起初遇到一些问题,因为我试图得到d/_next
,它从未返回任何内容)是获取下一组项目的正确URL。 __next
will only ever be a value if there is another set of items available to get. 如果有另一组可用项,则
__next
将只是一个值。
I ended up creating a RequestURL
variable which was initially set to to original request, but was changed to d/__next
at the end of the loop. 我最终创建了一个
RequestURL
变量,该变量最初设置为原始请求,但在循环结束时更改为d/__next
。 Then the loop went and checked if the RequestURL
was not empty before going inside the loop. 然后循环去检查
RequestURL
在进入循环之前是否为空。
Forgive my lack of code, I'm using SharePoint Designer 2013 to make this, and the syntax isn't horribly descriptive. 原谅我缺少代码,我正在使用SharePoint Designer 2013来实现这一点,而且语法并不是非常具有描述性。
If you'd only like a small set of data 如果你只喜欢一小组数据
There's probably a few situations where you would only want x
amount of rows from your list each time you go through the loop and that's real easy to do as well. 在某些情况下,每次进行循环时,您只需要列表中的
x
行数,这也很容易实现。
if you just add a $top=x
parameter to your request, the __next
URL that comes back with the response will give you the next x
rows from your list. 如果您只是在请求中添加
$top=x
参数,那么带有响应的__next
URL将为您提供列表中的下一行x
行。 Eventually when there are no rows left to return __next
won't be returned with the response. 最后,当没有剩下的行返回
__next
时,不会返回响应。
Don't forget that in order to use __next you need to have a 不要忘记,为了使用__next你需要有一个
$skiptoken=Paged=TRUE
in the url as well. 在网址中也是如此。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.