SP. ContentTypeCollection object (sp.js)

Representa una colección de tipos de contenido de lista o sitio web.

Última modificación: lunes, 9 de marzo de 2015

Hace referencia a: apps for SharePoint | SharePoint Foundation 2013 | SharePoint Server 2013

var object = new SP.ContentTypeCollection()

Miembros

El objeto ContentTypeCollection tiene los siguientes miembros.

Constructor

El objeto ContentTypeCollection tiene el siguiente constructor.

Constructor

Descripción

ContentTypeCollection

Inicializa una nueva instancia del objeto SP.ContentTypeCollection.

Métodos

El objeto ContentTypeCollection tiene los siguientes métodos.

Método

Descripción

Agregar

Agrega un tipo de contenido nuevo a la colección.

addExistingContentType

Agrega el tipo de contenido especificado a la colección.

getById

Devuelve el tipo de contenido con el identificador especificado de la colección.

itemAt

Obtiene el elemento en el índice especificado de la colección.

Propiedades

El objeto ContentTypeCollection tiene las siguientes propiedades.

Propiedad

Descripción

childItemType

Elemento

Obtiene el elemento en el índice especificado de la colección.

Ejemplo

En el ejemplo siguiente se crea un botón de entrada en una página de aplicación que inicializa un tipo de contenido personalizado, lo agrega a la colección de tipos de contenido y a continuación, muestra los nombres de los tipos de contenido del sitio Web actual.

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

var contentTypeCollection;

function runCode() {
    var clientContext = new SP.ClientContext.get_current();
    if (clientContext != undefined && clientContext != null) {
        var webSite = clientContext.get_web();

        this.contentTypeCollection = webSite.get_contentTypes();

        // Initialize a new content type.
        var contentInfo = new SP.ContentTypeCreationInformation();
        contentInfo.set_name('myContentType2');
        contentInfo.set_description('My custom content type 2');
        this.contentTypeCollection.add(contentInfo);

        clientContext.load(this.contentTypeCollection);
        clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
    }
}

function onQuerySucceeded() {
    var contentTypeinfo = '';
    var contentTypeEnumerator = this.contentTypeCollection.getEnumerator();
    while (contentTypeEnumerator.moveNext()) {
        var content = contentTypeEnumerator.get_current();
        contentTypeinfo += 'Content Type Name: ' + content.get_name() + '\n';
    }
    alert(contentTypeinfo);
}

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>

Extremo del recurso de REST

Estructura de URI de extremo

http://<sitecollection>/<site>/_api/web/lists(listid)/contenttypes

Solicitudes HTTP

Este recurso admite los siguientes comandos HTTP:

Sintaxis de GET

GET http://<sitecollection>/<site>/_api/web/lists(listid)/contenttypes

Sintaxis de POST

POST http://<sitecollection>/<site>/_api/web/lists(listid)/contenttypes