首页 > 代码库 > sharepoint ECMA using a custom contentType to creating a list in SubSite

sharepoint ECMA using a custom contentType to creating a list in SubSite

 Using a custom contentType to creating a list:

function GetContentType()
{
        var clientContext = new SP.ClientContext(siteUrl);
        var currentWeb = clientContext.get_web();
        var contentTypeCollection = currentWeb.get_contentTypes(); 
        var contentType = contentTypeCollection.getById("0x01010038CBF7FA14024D2688184E50E84E3239");
        clientContext.load(contentType);
        clientContext.executeQueryAsync(
                                        Function.createDelegate(this, onQuerySucceeded),
                                        Function.createDelegate(this, onQueryFailed)
                            );
}  

function onQuerySucceeded(){

            var count = subWebs.get_count();
            if (count > 0) {
                for (var i = 0; i < count; i++) {
                    var subWeb = subWebs.itemAt(i);
                    var list = subWeb.get_lists().getByTitle("12");
                    //get this list all contentType
                    var sublistContentTypeCollection = list.get_contentTypes();
                    //if this contentType is no add this contentType;
                    sublistContentTypeCollection.addExistingContentType(contentType);
                    clientContext.load(subWeb);
                    clientContext.load(list);
                    clientContext.load(sublistContentTypeCollection);
                    clientContext.executeQueryAsync(Function.createDelegate(this, onQuerySucceededContentType), Function.createDelegate(this, onQueryFailedContentType));
                }
            }
}
?
1
此处需要注意的是,必须通过主站点查找到下面的子站点,只有这样才能通过custom contentType 创建成功list