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));
                }
            }
}
此处需要注意的是,必须通过主站点查找到下面的子站点,只有这样才能通过custom contentType 创建成功list



转载于:https://www.cnblogs.com/lynn-lin/p/3775338.html

猜你喜欢

转载自blog.csdn.net/weixin_33682790/article/details/93639905