首页 > 其他 > 详细

sharepoint ECMA using a list template to creating a list in SubSIte

时间:2014-06-09 00:19:12      阅读:474      评论:0      收藏:0      [点我收藏+]

Using a list template to creating a list in SubSIte

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function CreateList(){
        var clientContext = new SP.ClientContext(siteUrl);
        var currentWeb = clientContext.get_web();
        var listTemplateCollection = currentWeb.get_listTemplates();
            clientContext.load(listTemplateCollection);
            clientContext.executeQueryAsync(
                Function.createDelegate(this, onQuerySucceededlistTemplate),
                Function.createDelegate(this, onQueryFailedlistTemplate)
            );
}<br>function onQuerySucceededlistTemplate() {
            var listTemplateEnumerator = listTemplateCollection.getEnumerator();
            var listtemplateInfo = "";
            while (listTemplateEnumerator.moveNext()) {
                var listTemp = listTemplateEnumerator.get_current();
                if (listTemp.get_name() == "OfficeDocument_List") {
                    var count = subWebs.get_count();
                    if (count > 0) {
                        for (var i = 0; i < count; i++) {
                            var subWeb = subWebs.itemAt(i);
                            if (subWeb.get_serverRelativeUrl() == self.selectedSiteName()) {
                                var listCreateInfo = new SP.ListCreationInformation();
                                listCreateInfo.set_title(self.DocumentName());
                                listCreateInfo.set_description(self.DocumentDescription());
                                listCreateInfo.set_templateType(listTemp.get_listTemplateTypeKind());
                                listCreateInfo.set_templateFeatureId(listTemp.get_featureId().toString());
                                oList = subWeb.get_lists().add(listCreateInfo);
                                clientContext.load(subWeb);
                                clientContext.load(oList);
                                clientContext.executeQueryAsync(
                                    Function.createDelegate(this, ExecuteOnSuccessList),
                                    Function.createDelegate(this, ExecuteOnFailureList)
                                );
                            }
                        }
                    }
                }
        }
}<br><br>1.此处需要注意的是,必须通过主站点查找到下面的子站点,只有这样才能通过custom list template 创建成功list<br>2.创建list的必须设置featureID:listCreateInfo.set_templateFeatureId(listTemp.get_featureId().toString());<em id="__mceDel">否则会创建不成功,并且报一个Invaild contentType Name错误.</em>

  

sharepoint ECMA using a list template to creating a list in SubSIte,布布扣,bubuko.com

sharepoint ECMA using a list template to creating a list in SubSIte

原文:http://www.cnblogs.com/lynn-lin/p/3775344.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!