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

旧城等待, 2021-12-23 04:11 295阅读 0赞

Using a custom contentType to creating a list:

  1. function GetContentType()
  2. {
  3. var clientContext = new SP.ClientContext(siteUrl);
  4. var currentWeb = clientContext.get_web();
  5. var contentTypeCollection = currentWeb.get_contentTypes();
  6. var contentType = contentTypeCollection.getById("0x01010038CBF7FA14024D2688184E50E84E3239");
  7. clientContext.load(contentType);
  8. clientContext.executeQueryAsync(
  9. Function.createDelegate(this, onQuerySucceeded),
  10. Function.createDelegate(this, onQueryFailed)
  11. );
  12. }
  13. function onQuerySucceeded(){
  14. var count = subWebs.get_count();
  15. if (count > 0) {
  16. for (var i = 0; i < count; i++) {
  17. var subWeb = subWebs.itemAt(i);
  18. var list = subWeb.get_lists().getByTitle("12");
  19. //get this list all contentType
  20. var sublistContentTypeCollection = list.get_contentTypes();
  21. //if this contentType is no add this contentType;
  22. sublistContentTypeCollection.addExistingContentType(contentType);
  23. clientContext.load(subWeb);
  24. clientContext.load(list);
  25. clientContext.load(sublistContentTypeCollection);
  26. clientContext.executeQueryAsync(Function.createDelegate(this, onQuerySucceededContentType), Function.createDelegate(this, onQueryFailedContentType));
  27. }
  28. }
  29. }
  30. 此处需要注意的是,必须通过主站点查找到下面的子站点,只有这样才能通过custom contentType 创建成功list

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

发表评论

表情:
评论列表 (有 0 条评论,295人围观)

还没有评论,来说两句吧...

相关阅读