2016-11-08 74 views
0

我想检索JS中sharepoint List的标题。在javascript中检索sharepoint列表

我的功能JS:

function retrieveAllListsAllFields() { 
     var ctx = SP.ClientContext.get_current(); 
     var web = ctx.get_web(); 
     ctx.load(web, "Title"); 

    ctx.executeQueryAsync(
    Function.createDelegate(this, function(){ 
     var listTitle = web.get_title() + " Documents"; 
    }), 
    Function.createDelegate(this, this.onQueryFailed) 
    ); 

我检索列表中,但我想利用这个列表中的另一个功能让我的库文件列表在组合框中:

function initComboBox(fileslistBox, fileslistBoxDest, selectLibraryFileFieldResult, entityComboBox, yearComboBox, typeComboBox, library, entityValue, currentSiteUrl) { 
    function retrieveAllListsAllFields() { 
     var ctx = SP.ClientContext.get_current(); 
     var web = ctx.get_web(); 
     ctx.load(web, "Title"); 

     ctx.executeQueryAsync(
     Function.createDelegate(this, function(){ 
      var listTitle = web.get_title() + " Documents"; 
     }), 
     Function.createDelegate(this, this.onQueryFailed) 
     ); 

    var listBox; 
    var i = 0; 
    var reggie = /(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/; 
    var entityComboBoxArray = new Array(); 
    var yearComboBoxArray = new Array(); 
    var typeComboBoxArray = new Array(); 

    addItemToArray(entityComboBoxArray, "", "", i); 
    addItemToArray(yearComboBoxArray, "", "", i); 
    addItemToArray(typeComboBoxArray, "", "", i); 

    //init all combox 
    $().SPServices({ 
     operation: "GetListItems", 
     webURL: currentSiteUrl, 
     async: true, 
     listName: listTitle,   
     CAMLViewFields: "<ViewFields><FieldRef Name='ID' /><FieldRef Name='FileLeafRef' /><FieldRef Name='File_x0020_Type' /><FieldRef Name='Title' /><FieldRef Name='Entity' /><FieldRef Name='Year_Document' /><FieldRef Name='Library' /></ViewFields>", 
     CAMLQuery: "<Query><OrderBy><FieldRef Name='Title' /></OrderBy><Where><Eq><FieldRef Name='Library' /><Value Type='Choice'>" + library + " </Value></Eq></Where></Query>", 
     completefunc: function (xData, Status) { 
      $(xData.responseXML).SPFilterNode("z:row").each(function() { 
       i++; 
       //Add value to combox Array 
       alert(listTitle); 
       var tmpEntity = $(this).attr("ows_Entity"); 
       if (tmpEntity != null) 
        addItemToArray(entityComboBoxArray, $(this).attr("ows_Entity"), (tmpEntity).split("#")[1], i); 

       var tmpYear = $(this).attr("ows_Year_Document"); 
       if (tmpYear != null) 
        addItemToArray(yearComboBoxArray, tmpYear, tmpYear, i); 

       var tmpType = $(this).attr("ows_File_x0020_Type"); 
       if (tmpType != null) 
        addItemToArray(typeComboBoxArray, tmpType, tmpType, i); 

       //if option already in Result Select, we move it to the destination RadListBox 
       if (isOptionContainInSelect(selectLibraryFileFieldResult, $(this).attr("ows_Title")) == true) 
        listBox = fileslistBoxDest; 
       else listBox = fileslistBox; 
       addNewFilesItem($(this).attr("ows_ID"), $(this).attr("ows_FileLeafRef"), $(this).attr("ows_Title"), $(this).attr("ows_Entity"), $(this).attr("ows_Year_Document"), $(this).attr("ows_File_x0020_Type"), listBox); 
      }); 


      //Add sorted array value to combobox 
      addArrayItemsToComboBox(entityComboBoxArray.sort(), entityComboBox); 
      addArrayItemsToComboBox(yearComboBoxArray.sort(), yearComboBox); 
      addArrayItemsToComboBox(typeComboBoxArray.sort(), typeComboBox); 
      selectValueForComboBox(entityComboBox, entityValue); 
      filterList(fileslistBox, entityComboBox, yearComboBox, typeComboBox); 
     } 
    }); 
    } 
} 

但我无法检索图书馆中的文件。 这些文档不会加载到我的组合框中。

这不可能使用这个“listName:listTitle”?

最好的问候,

回答

0

executeQueryAsync有两个参数:回调函数,当查询成功运行,并且回调函数,如果查询运行到任何错误运行。

取决于查询成功运行的任何代码应该放入里面的成功回调函数(第一个参数为executeQueryAsync)。

ctx.executeQueryAsync(
Function.createDelegate(this, 
    function(){ 
     var listTitle = web.get_title() + " Documents"; 

     var listBox; 
     var i = 0; 
     var reggie // ... 
     // rest of your code goes here... 

    }),Function.createDelegate(this, this.onQueryFailed) 
); 
+0

完美,很好!谢谢 !! – user2814368