SP.FieldCollection object
Represents a collection of SP.Field objects.
Last modified: March 09, 2015
Applies to: apps for SharePoint | SharePoint Foundation 2013 | SharePoint Server 2013
var object = new SP.FieldCollection()
The FieldCollection object has the following members.
Constructor
The FieldCollection object has the following constructor.
|
Constructor |
Description |
|---|---|
|
Initializes a new instance of the SP.FieldCollection object. |
Methods
The FieldCollection object has the following methods.
|
Method |
Description |
|---|---|
|
Adds a field to the field collection. |
|
|
Adds a secondary lookup field that depends on a primary lookup field for its relationship to the list where it gets its information. |
|
|
Creates a field based on the specified schema, Boolean value, and field options. |
|
|
Gets the field with the specified ID. |
|
|
Returns the first Field object with the specified internal name or title from the collection. |
|
|
Returns the first field object in the collection based on the title of the specified field. |
|
|
|
|
|
Gets the field at the specified index in the collection. |
Properties
The FieldCollection object has the following properties.
|
Property |
Description |
|---|---|
|
|
|
|
Gets the specified field from the collection. |
|
|
Specifies the XML schema of the collection of fields. |
The following example creates an input button on an application page that uses the FieldCollection collection to display the available fields in the Announcements list.
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server"> <script type="text/ecmascript" language="ecmascript"> var fieldCollection; function runCode() { var clientContext = new SP.ClientContext(); var targetList = clientContext.get_web().get_lists().getByTitle('Announcements'); fieldCollection = targetList.get_fields(); clientContext.load(fieldCollection, 'Include(Title)'); clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed)); } function onQuerySucceeded() { var message = "The following fields are available in the Announcements list:\n\n"; var fields = ''; var listEnumerator = fieldCollection.getEnumerator(); while (listEnumerator.moveNext()) { fields += listEnumerator.get_current().get_title() + "; "; } alert(message + fields); } function onQueryFailed(sender, args) { alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); } </script> <input id="Button1" type="button" value="Run Code" onclick="runCode()" /> </asp:Content>
See FieldCollection resource for more information.
Endpoint URI structure
http://<sitecollection>/<site>/_api/web/lists(listid)/fields