Compartilhar via


SP.List.getItems(query_) Method

Applies to: SharePoint Foundation 2010

In this article
Return Value
Remarks
Applies To

Returns a collection of items from the list based on the specified query.

var value = SP.List.getItems(query_);

Parameters

Type: SP.CamlQuery

Return Value

Type: SP.ListItemCollection

Exceptions

  • SPException
    The field specified in the query is not present in the list. Error code: -2130575340.
  • SPQueryThrottledException
    The throttling limit is exceeded by the operation. Error code: -2147024860.Or there is a lack of resources available to process the request. Error code: -2147024749.

Remarks

It must not be null.

Applies To

SP.List Class

Example

The following example creates an input button on an application page that gets announcements in the current web site that contain the text announce.

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

var listItems;

function runCode() {
  var clientContext = new SP.ClientContext();
  var targetList = clientContext.get_web().get_lists().getByTitle('Announcements');
  var query = new SP.CamlQuery();
  query.set_viewXml("<View><Query><Where><Contains><FieldRef Name='Title'/><Value Type='Text'>announce</Value></Contains></Where></Query></View>");
  listItems = targetList.getItems(query);
  clientContext.load(listItems);
  clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}

function onQuerySucceeded() {
  var listEnumerator = listItems.getEnumerator();
  while (listEnumerator.moveNext()) {
    alert("Item containing ‘announce’ found! \nTitle: " + listEnumerator.get_current().get_item("Title"));
  }  
}

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.List Methods

SP.List Properties

SP Namespace