Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Sharepoint Online executeQueryAsync JSOM-返回值_Javascript_Sharepoint - Fatal编程技术网

Javascript Sharepoint Online executeQueryAsync JSOM-返回值

Javascript Sharepoint Online executeQueryAsync JSOM-返回值,javascript,sharepoint,Javascript,Sharepoint,使用Sharepoint Online 2013使用JSOM构建应用程序。 当前部分是在将数据提交到列表(正常工作)后,将打开一个模式,允许用户根据该列表和其他列表创建PDF。目前的问题是,列表中的数据必须在客户端准备好,然后我才能开始将其制作成PDF。我已经阅读了有关“承诺”方法的文献,这就是我最近尝试的方法,但收效甚微 函数getQuoteDetails(){ 警报(“无”);一些建议 确保您使用的是jQuery版本>=1.5,因为延迟的对象 是在jQuery1.5中引入的 无需要为SP.

使用Sharepoint Online 2013使用JSOM构建应用程序。 当前部分是在将数据提交到列表(正常工作)后,将打开一个模式,允许用户根据该列表和其他列表创建PDF。目前的问题是,列表中的数据必须在客户端准备好,然后我才能开始将其制作成PDF。我已经阅读了有关“承诺”方法的文献,这就是我最近尝试的方法,但收效甚微

函数getQuoteDetails(){


警报(“无”);一些建议

  • 确保您使用的是jQuery版本>=1.5,因为
    延迟的对象
    是在jQuery1.5中引入的
  • 需要为
    SP.ClientContext.load
    函数的第二个参数指定CAML
    视场
    和值,因为它们都用于指定要检索的属性
  • 始终希望包含函数的失败回调,以便处理任何发生的错误
话虽如此,我建议您使用以下更通用的方法获取列表项:

function getListItems(listTitle,propertiesToInclude)
{ 
   var ctx = SP.ClientContext.get_current();
   var web = ctx.get_web();
   var list =  web.get_lists().getByTitle(listTitle);
   var items = list.getItems(SP.CamlQuery.createAllItemsQuery());
   var includeExpr = 'Include(' + propertiesToInclude.join(',') + ')';
   ctx.load(items,includeExpr); 
   var d = $.Deferred();
   ctx.executeQueryAsync(function() {
       var result = items.get_data().map(function(i){
           return i.get_fieldValues();   
       });
       d.resolve(result);
   },
   function(sender,args){
       d.reject(args);
   });
   return d.promise();
}
在这种情况下,可以检索列表项,如下所示:

SP.SOD.executeFunc('SP.js', 'SP.ClientContext', function() {

   var listTitle = 'Documents';  //set list title here
   var properties = ['Title','ID'];  //specify items properties here
   getListItems(listTitle,properties)
   .done(function(items){
      console.log(items);
   })
   .fail(function(error){
      console.log(error.get_message()); //if any error is occurred?
    });

}); 

这看起来很好,通用框架将大大减少代码。尽管我有一些问题要问你。如果你注意到CAML查询,“.”非常重要,因为我只需要返回某些值,列表可能会很大(900+)正因为如此,我担心返回数组中的整个列表可能会非常慢。-首先,我可以问一下我返回命名数组是什么吗?关于
ViewFields
,propertiesToInclude参数
SP.ClientContext.load(clientObject,propertiesToInclude)
也有同样的目的,特别是明确指定要检索的属性。我更多的是在数据检索过程中指定WHERE子句。但是我可以得到整个数组,并使用jquery删除非结果
function getListItems(listTitle,propertiesToInclude)
{ 
   var ctx = SP.ClientContext.get_current();
   var web = ctx.get_web();
   var list =  web.get_lists().getByTitle(listTitle);
   var items = list.getItems(SP.CamlQuery.createAllItemsQuery());
   var includeExpr = 'Include(' + propertiesToInclude.join(',') + ')';
   ctx.load(items,includeExpr); 
   var d = $.Deferred();
   ctx.executeQueryAsync(function() {
       var result = items.get_data().map(function(i){
           return i.get_fieldValues();   
       });
       d.resolve(result);
   },
   function(sender,args){
       d.reject(args);
   });
   return d.promise();
}
SP.SOD.executeFunc('SP.js', 'SP.ClientContext', function() {

   var listTitle = 'Documents';  //set list title here
   var properties = ['Title','ID'];  //specify items properties here
   getListItems(listTitle,properties)
   .done(function(items){
      console.log(items);
   })
   .fail(function(error){
      console.log(error.get_message()); //if any error is occurred?
    });

});