jsom sharepoint 2010 循环获取多个list的item值

	        <script type="text/javascript">

	        // <![CDATA[



                var chongdianbaId;

	        var elm = document.getElementById("idAttachmentsTable");

	        var elmAttachmentRow =  document.getElementById("idAttachmentsRow");

	        if ((elm == null || elm.rows.length == 0) && (elmAttachmentRow!=null)){

	            elmAttachmentRow.style.display='none';

		}else{

                    var attachmenturl = GetAttachmentsUrl().split(";")[0];

                    chongdianbaId = attachmenturl.split("/")[7];

                    ExecuteOrDelayUntilScriptLoaded(GetChongDianBaName,"SP.js");

                }

                //获取附件url地址集合

                function GetAttachmentsUrl(){

                    var urls;

                    var locUrl = window.location.href;

	            if (locUrl.indexOf("doccenter/Lists/List1/DispForm.aspx") != -1){

                        var td = elm.getElementsByTagName("td");

                        var len = td.length;

                        for (i = 0; i < len; i++) {

                            var a = td[i].getElementsByTagName("a")

                            urls += a[0].href + ";";

		        }

		    }

                    return urls;

                }

                //获取充电吧标题

                var chongdianbaName;

                var chongdianba;

                function GetChongDianBaName() {

                    var ctx = new SP.ClientContext.get_current();

                    var web  = ctx.get_web();

                    var list = web.get_lists().getByTitle("充电吧"); 

                    var camlQuery = new SP.CamlQuery();

                    camlQuery.set_viewXml('<View><Query><Where><Contains><FieldRef Name=\'ID\'/>' + '<Value Type=\'Counter\'>'+ chongdianbaId + '</Value></Contains></Where></Query><RowLimit>10</RowLimit></View>');

                    this.chongdianba = list.getItems(camlQuery);

                    ctx.load(this.chongdianba, "Include(Title)");

                    ctx.executeQueryAsync(Function.createDelegate(this,this.onSuccess0),Function.createDelegate(this,this.onFailed0));

                }

                function onSuccess0(sender, args) { 

                    var count = 0;

                                       

                    var listEnumerator = this.chongdianba.getEnumerator();

                    while (listEnumerator.moveNext()) {

                        count = count + 1;

                        var currentItem = listEnumerator.get_current();

                        chongdianbaName += currentItem.get_item('Title').toString();

                    }

                    chongdianbaName = chongdianbaName.replace('undefined','');

                    alert(chongdianbaName);

                    ExecuteOrDelayUntilScriptLoaded(GetAttachmentFolderName,"SP.js");

                }

                function onFailed0(sender, args) {

                    alert('failed. Message:' + args.get_message());

                }

                //获取KnowledgeLibrary内容

                var folderName; 

                var knowledgeLibrary;

                function GetAttachmentFolderName() {

                    var ctx = new SP.ClientContext("/");

                    var web  = ctx.get_web();

                    var list = web.get_lists().getByTitle("KnowledgeLibrary"); 

                    var camlQuery = new SP.CamlQuery();

                    camlQuery.set_viewXml('<View><Query><Where><Contains><FieldRef Name=\'Title\'/>' + '<Value Type=\'Text\'>'+ chongdianbaName + '</Value></Contains></Where></Query><RowLimit>10</RowLimit></View>');

                    this.knowledgeLibrary = list.getItems(camlQuery);

                    ctx.load(this.knowledgeLibrary, "Include(dtAttachmentFolderName,dtAttachmentListName)");

                    ctx.executeQueryAsync(Function.createDelegate(this,this.onSuccess),Function.createDelegate(this,this.onFailed));

                }

                function onSuccess(sender, args) { 

                    var count = 0;

                                       

                    var listEnumerator = this.knowledgeLibrary.getEnumerator();

                    while (listEnumerator.moveNext()) {

                        count = count + 1;

                        var currentItem = listEnumerator.get_current();

                        folderName += currentItem.get_item('dtAttachmentFolderName').toString();

                    }

		    folderName = folderName.replace('undefined','')

                    alert(folderName);

                    ExecuteOrDelayUntilScriptLoaded(GetAttachmentItemID,"SP.js");

                }

                function onFailed(sender, args) {

                    alert('failed. Message:' + args.get_message());

                }

                //获取附件id

                var attachmentFiles;

                var attachmentIDs;

                function GetAttachmentItemID() {

                    var ctx = new SP.ClientContext("/");

                    var web  = ctx.get_web();

                    var attachmentFolder = web.getFolderByServerRelativeUrl('/DentsuDocumentLibraryAttachments/' + folderName);

                    this.attachmentFiles = attachmentFolder.get_files();

                    ctx.load(this.attachmentFiles);

                    ctx.executeQueryAsync(Function.createDelegate(this,this.onSuccess1),Function.createDelegate(this,this.onFailed1));

                }

                function onSuccess1(sender, args) { 

                    var listEnumerator = this.attachmentFiles.getEnumerator();

                    while (listEnumerator.moveNext()) {

                        var currentItem = listEnumerator.get_current();

                        attachmentIDs += currentItem.get_item('ID').toString() + ';';

                    }

                    alert(attachmentIDs);

                }

                function onFailed1(sender, args) {

                    alert('failed. Message:' + args.get_message());

                }

  

你可能感兴趣的:(SharePoint)