首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >SharePoint列表中的大列表检索在工作前失败4-10次(JavaScript)

SharePoint列表中的大列表检索在工作前失败4-10次(JavaScript)
EN

Stack Overflow用户
提问于 2018-06-01 23:27:06
回答 1查看 116关注 0票数 0

我需要在列表之间复制项目(向每个项目添加更多的东西,所以不能使用流),如果源列表大于100个项,脚本将在查询时终止到源列表中(第一件事是按一下按钮),大约要执行4到10次。

我使用承诺来确保一切按顺序进行,但这似乎不是问题所在,而是查询失败,这是承诺结构的第一步。

它不是查询中的行限制,因为它被设置为1000,行数约为200。

下面是一个示例代码,它可以很好地处理少量的项,但是当两个列表都包含大约100个项时,需要多次运行:

代码语言:javascript
运行
复制
<head>
    <script
  src="https://code.jquery.com/jquery-3.3.1.js"
  integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
  crossorigin="anonymous"></script>
    <script>

    function update() {
        console.log("1")
  var dfd = $.Deferred(function () {
    var updateBtnCLientContextForSourceList = 
      new SP.ClientContext.get_current();
    var getSourceList = updateBtnCLientContextForSourceList
        .get_web()
        .get_lists()
        .getByTitle("SourceList");
    var camlQueryForSourceList = new SP.CamlQuery();
    camlQueryForSourceList.set_viewXml('<View><Query><Where><Geq><FieldRef Name=\'ID\'/>' +
      '<Value Type=\'Number\'>1</Value></Geq></Where></Query><RowLimit>4000</RowLimit></View>');
    var SourceListtStore = getSourceList.getItems(camlQueryForSourceList);
    updateBtnCLientContextForSourceList.load(SourceListtStore);
    updateBtnCLientContextForSourceList.executeQueryAsync(
      function () {
        dfd.resolve(SourceListtStore);
      },
      function (sender, args) {
        dfd.reject(args);
      }
    );
  });
         console.log("2")
  return dfd.promise();
}

acadcount = 0;

function check() {
  update()
  .then(
    function (SourceListtStore) {
         console.log("3")
      acadcount = SourceListtStore.get_count()
         console.log("4")
      var dfd = $.Deferred(
        function () {
          var updateBtnCLientContextForWeeksAllocated = 
            SP.ClientContext.get_current();
          var getWeeksAllocated = 
            updateBtnCLientContextForWeeksAllocated
              .get_web()
              .get_lists()
              .getByTitle("Weeks Allocated");
          var camlQueryForWeeksAllocated = new SP.CamlQuery();
          camlQueryForWeeksAllocated.set_viewXml('<View><Query><Where><Geq><FieldRef Name=\'ID\'/>' +
            '<Value Type=\'Number\'>1</Value></Geq></Where></Query><RowLimit>1000</RowLimit></View>');
          var weeksAllocatedListStore = 
            getWeeksAllocated.getItems(camlQueryForWeeksAllocated);
          updateBtnCLientContextForWeeksAllocated.load(weeksAllocatedListStore);
          updateBtnCLientContextForWeeksAllocated.executeQueryAsync(
            function () {
              dfd.resolve(weeksAllocatedListStore);
            },
            function (sender, args) {
              dfd.reject(args);
            }
          );
        }
      );
         console.log("5")
      return dfd.promise()
    }
  ).then(
    function (waListStore) {
         console.log("6")
      if (waListStore.get_count() === acadcount) {
           console.log("7")
        alert("All items have been copied")
      }
      else {
           console.log("8")
        alert("Please try again")
      }
    }
  );
}

    </script>


</head>

<body>
    <button onClick="check()">Check</button>


</body>
  • 在返回源列表的查询结果之前进行2=just阶段
  • 在返回分配的周列表查询之前进行5=just阶段 结果

源列表:2项,周分配:3项

  • 第一和第二轮:最多8次(已完成)

来源列表:109个项目,周分配:1个项目

  • 第一轮:最多2次
  • 2,3:最多5
  • 4:最多2
  • 5-8:最多5
  • 9:最多8(已完成)

来源列表:109个项目,周分配:100个项目

  • 前33场:最多5场
  • 34:最多8(已完成)

那么,我是否正确地假设,当脚本失败时,promise.return会在.resolve完成之前运行?如果是这样的话,我怎样才能避开这一切呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-05 07:29:18

在JS有机会使用大量的项完全执行之前,该页面正在重新加载,禁用了按钮单击上的刷新功能,现在可以正常工作了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50652099

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档