Condividi tramite


SP.ListItemCollectionPosition Class

Applies to: SharePoint Foundation 2010

Specifies the information required to get the next page of data for a list view.

SP.ListItemCollectionPosition

Inherits

SP.ClientValueObject Class

Example

The following example creates an input button on an application page that displays titles from the list of announcements on the current web site two at a time.

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<script type="text/ecmascript" language="ecmascript">

var listItems;                   // The list of retrieved items.
var query;                       // For paging, reuse the same query object.
var targetList;                  // The list from which to retrieve items.
var clientContext;

function runCode() {
  clientContext = new SP.ClientContext();
  targetList = clientContext.get_web().get_lists().getByTitle('Announcements');
  query = new SP.CamlQuery();
  query.set_viewXml("<View><ViewFields><FieldRef Name='Title'/></ViewFields><RowLimit>2</RowLimit></View>");
  listItems = targetList.getItems(query);
  clientContext.load(listItems); 
  clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}

function onQuerySucceeded() {
  var message = "Titles, two at a time:\n";
  var listEnumerator = listItems.getEnumerator();
  while (listEnumerator.moveNext())  {
    message += "\nTitle=" + listEnumerator.get_current().get_item("Title")
  }
  alert(message);
  var position = listItems.get_listItemCollectionPosition();
  if (position != null) {
    query.set_listItemCollectionPosition(position);
    listItems = targetList.getItems(query);
    clientContext.load(listItems);  
    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
  }
  
}

function onQueryFailed(sender, args) {
  alert('Request failed. \nError: ' + args.get_message() + '\nStackTrace: ' + args.get_stackTrace());
}
</script>

    <input id="Button1" type="button" value="Run Code" onclick="runCode()" />

</asp:Content>

See Also

Reference

SP.ListItemCollectionPosition Methods

SP.ListItemCollectionPosition Properties

SP Namespace