IE11中未执行jQuery附加功能

时间:2019-06-03 23:55:47

标签: javascript jquery sharepoint-online

我有以下代码:

if (document.readyState === "loading") {
    document.addEventListener("DOMContentLoaded", LoadProd);
} else {
    LoadProd();
}

function LoadProd() {
  var restUrl = "https://tenant.sharepoint.com/sites/site/Negocio/OfertaParticulares/_api/web/lists/GetByTitle('1%20-%20Produtos%20-%20Conteúdos%20em%20blocos')/GetItems(query=@v1)?@v1=" + "{\"ViewXml\":\"<View Scope='RecursiveAll'><Query><Where><And><Eq><FieldRef Name='ContentType' /><Value Type='Computed'>DinamicoFolder</Value></Eq><And><Neq><FieldRef Name='Intranet_DestaqueOrdem' /><Value Type='Number'>100</Value></Neq><And><IsNotNull><FieldRef Name='Intranet_SubCategoria' /></IsNotNull><IsNotNull><FieldRef Name='Title' /></IsNotNull></And></And></And></Where><OrderBy><FieldRef Name='Intranet_DestaqueOrdem' Ascending='True' /></OrderBy></Query></View>\"}";
  jQuery.ajax({
    url: restUrl,
    method: "POST",
    headers: {
      "Accept": "application/json; odata=verbose",
      "X-RequestDigest": document.getElementById("__REQUESTDIGEST").value,
    },
    success: function(data) {
      //var upRefinadorSearch = setInterval(function () {
      //setTimeout(function() {
      var dataresult = data.d.results;
      dataresult = [].slice.call(dataresult);
      dataresult.forEach(function(key, value) {
        GetTagFolder = (key.Intranet_SubCategoria.results["0"].Label);
        FirstFolderProd = (key.Title);
        FirstFolderWithoutSpaceProd = FirstFolderProd.replace(/[^a-z0-9\s]/gi, '').replace(/[_\s]/g, '');

        jQuery("#SubFolders").append("<div id='PROD" + FirstFolderWithoutSpaceProd + "'></div>");
        ReceivePages(FirstFolderProd, FirstFolderWithoutSpaceProd, GetTagFolder);
      });
      /*clearInterval(upRefinadorSearch);
        }, 2500);*/
    },
    error: function(error) {
      console.log(error);
    }
  });
}


function ReceivePages(FirstFolderProd, FirstFolderWithoutSpaceProd, GetTagFolder) {
  var restUrl = "https://tenant.sharepoint.com/sites/site/Negocio/OfertaParticulares/_api/web/lists/GetByTitle('2 - Produtos - Páginas')/GetItems(query=@v1)?@v1=" + "{\"ViewXml\":\"<View Scope='RecursiveAll'><Query><Where><And><Eq><FieldRef Name='ContentType' /><Value Type='Computed'>Produto</Value></Eq><And><Eq><FieldRef Name='Intranet_SubCategoria' /><Value Type='TaxonomyFieldTypeMulti'>" + GetTagFolder + "</Value></Eq><And><Eq><FieldRef Name='OfertaEmComercializa_x00e7__x00e3_o' /><Value Type='Boolean'>1</Value></Eq><Eq><FieldRef Name='_ModerationStatus' /><Value Type='ModStat'>0</Value></Eq></And></And></And></Where><OrderBy><FieldRef Name='OrdenarGrupo' Ascending='True' /></OrderBy></Query></View>\"}";
  jQuery.ajax({
    url: restUrl,
    //async: false,
    method: "POST",
    headers: {
      "Accept": "application/json; odata=verbose",
      "X-RequestDigest": document.getElementById("__REQUESTDIGEST").value,
    },
    success: function(data) {
      //var upRefinadorSearch = setInterval(function () {
      var uniqueNames = [];
      for (i = 0; i < data.d.results.length; i++) {

        if (uniqueNames.indexOf(data.d.results[i].SubFamiliaParticulares.results["0"].Label) === -1) {
          var SubTabs = data.d.results[i].SubFamiliaParticulares.results["0"].Label;
          var SubTabsWithoutSpace = SubTabs.replace(/[^a-z0-9\s]/gi, '').replace(/[_\s]/g, '');
          if (SubTabs !== "Não definido") {
            if (jQuery("#IDcontainerOfertasProd" + FirstFolderWithoutSpaceProd).length === 0) {
              var CreateFirstExpandableProd = '<div class="containerOfertasProd" id="IDcontainerOfertasProd' + FirstFolderWithoutSpaceProd + '"><div class="headerOfertasProd" id="IDheaderOfertasProd' + FirstFolderWithoutSpaceProd + '" data-SecondFolderNameProd="' + FirstFolderProd + '"><span id="ExpandableNameProd">' + FirstFolderProd + '<span id="ExpandSign" class="ExpandSignClassProd" style="float:right !important; font-size: 2.5rem; margin-top: -11px;">+</span></span></div><div class="contentOfertasProd" id="IDcontentOfertasProd' + FirstFolderWithoutSpaceProd + '"><div class="tabs-list"><ul id="dentroexpandableProd' + FirstFolderWithoutSpaceProd + '" class="grid-container-item wt-l1-container-pow0000004579item__background__border" data-ng-init="vm.itemSizeMobile = vm.itemSizeMobile || 1;vm.itemSizeTablet = vm.itemSizeTablet || 1;vm.itemSizeDesktop = vm.itemSizeDesktop || 1;vm.itemSizeLarge = vm.itemSizeLarge || 1"></ul><div class="pagination-template" data-ng-if="vm.isPaginate" data-ng-include="vm.paginationTemplate"></div></div><div id="AddContentProd' + FirstFolderWithoutSpaceProd + '"></div></div></div>';
              jQuery("#PROD" + FirstFolderWithoutSpaceProd).append(CreateFirstExpandableProd);
            }

            if (jQuery("#DETabsProd" + FirstFolderWithoutSpaceProd + SubTabsWithoutSpace).length === 0) {
              jQuery("#dentroexpandableProd" + FirstFolderWithoutSpaceProd).append("<li id='DETabsProd" + FirstFolderWithoutSpaceProd + SubTabsWithoutSpace + "' style='margin-left: 10px !important;color: black;' data-SubTab='" + SubTabs + "' data-FirstFolderWithoutSpaceProd='" + FirstFolderWithoutSpaceProd + "' data-Tag='" + GetTagFolder + "' class='loadContentProd'><a style='margin-left: 5px !important;color: black;' class='ng-binding'>" + SubTabs + "</a></li>");
              jQuery('[id^="DETabsProd' + FirstFolderWithoutSpaceProd + '"]').first().addClass('ActiveTabOfertas');
            }
          } else {
            if (jQuery("#IDcontainerOfertasProd" + FirstFolderWithoutSpaceProd).length === 0) {
              var CreateFirstExpandableProdWithoutTag = '<div class="containerOfertasProd" id="IDcontainerOfertasProd' + FirstFolderWithoutSpaceProd + '"><div class="headerOfertasProd" id="IDheaderOfertasProd' + FirstFolderWithoutSpaceProd + '" data-SecondFolderNameProd="' + FirstFolderProd + '"><span id="ExpandableNameProd">' + FirstFolderProd + '<span id="ExpandSign" class="ExpandSignClassProd" style="float:right !important; font-size: 2.5rem; margin-top: -11px;">+</span></span></div><div class="contentOfertasProd" id="IDcontentOfertasProd' + FirstFolderWithoutSpaceProd + '"><div id="AddContentProd' + FirstFolderWithoutSpaceProd + '"></div></div></div>';
              jQuery("#PROD" + FirstFolderWithoutSpaceProd).append(CreateFirstExpandableProdWithoutTag);
            }
          }
        }
      }
      /*clearInterval(upRefinadorSearch);
      }, 2500);*/
      if (jQuery("#PROD" + FirstFolderWithoutSpaceProd).length >= 1) {
        if (jQuery('[id^=DETabsProd' + FirstFolderWithoutSpaceProd + ']').length > 0) {
          OpenFirstProd(FirstFolderWithoutSpaceProd, GetTagFolder);
        } else {
          OpenFirstProdWithoutGrupo(FirstFolderWithoutSpaceProd, GetTagFolder);
        }
      }

    },
    error: function(error) {
      console.log(error);
    }
  });
}

此代码可在google,firefox和Edge中使用,但我的客户端使用IE11作为默认浏览器。 在谷歌的结果是这样的: enter image description here

使用IE 11打开时,不执行附加功能,也没有给我任何错误。 我已经尝试使用 setTimeout setInterval 函数,我认为这是问题所在。正如您在下面的代码中看到的那样,我已经尝试过 setInterval

function LoadProd() {
  var restUrl = "https://tenant.sharepoint.com/sites/site/Negocio/OfertaParticulares/_api/web/lists/GetByTitle('1%20-%20Produtos%20-%20Conteúdos%20em%20blocos')/GetItems(query=@v1)?@v1=" + "{\"ViewXml\":\"<View Scope='RecursiveAll'><Query><Where><And><Eq><FieldRef Name='ContentType' /><Value Type='Computed'>DinamicoFolder</Value></Eq><And><Neq><FieldRef Name='Intranet_DestaqueOrdem' /><Value Type='Number'>100</Value></Neq><And><IsNotNull><FieldRef Name='Intranet_SubCategoria' /></IsNotNull><IsNotNull><FieldRef Name='Title' /></IsNotNull></And></And></And></Where><OrderBy><FieldRef Name='Intranet_DestaqueOrdem' Ascending='True' /></OrderBy></Query></View>\"}";

  jQuery.ajax({
    url: restUrl,
    method: "POST",
    headers: {
      "Accept": "application/json; odata=verbose",
      "X-RequestDigest": document.getElementById("__REQUESTDIGEST").value,
    },
    success: function(data) {
      var upRefinadorSearch = setInterval(function() {
        var dataresult = data.d.results;
        dataresult = [].slice.call(dataresult);
        dataresult.forEach(function(key, value) {
          GetTagFolder = (key.Intranet_SubCategoria.results["0"].Label);
          FirstFolderProd = (key.Title);
          FirstFolderWithoutSpaceProd = FirstFolderProd.replace(/[^a-z0-9\s]/gi, '').replace(/[_\s]/g, '');

          jQuery("#SubFolders").append("<div id='PROD" + FirstFolderWithoutSpaceProd + "'></div>");

        });
        clearInterval(upRefinadorSearch);
      }, 2500);
    },
    error: function(error) {
      console.log(error);
    }
  });
}

使用setInterval可以创建div,但是GetPages function(如果我放置setInterval只能使用一次)。我的问题是我应该在哪里使用setTimeout和/或setInterval来执行附加函数?

0 个答案:

没有答案