【问题标题】:Run method only on first load of jqgrid仅在第一次加载 jqgrid 时运行方法
【发布时间】:2012-02-23 07:55:53
【问题描述】:

当我加载我的 jqgrid 时,我会在 loadcomplete 部分按以下方式填充我的过滤器工具栏选择框:

$(".ui-search-toolbar").find("select").each(function (index, value) {
    getDropdowndata($(this).attr('NAME'));
});

问题是每次重新加载网格时都会运行此代码。这会导致选择框在我单击多个页面时填充多个值。

我想要的是仅在第一次加载网格时运行此代码。

【问题讨论】:

    标签: jquery jqgrid


    【解决方案1】:

    最简单的解决方案是使用布尔变量并检查填充是否已经完成

    var isPopulated = false;
    
    ...
    
    function onLoadComplete(){
       if(!isPopulated){
          //your code here
          isPopulated = true;
       }
    }
    

    【讨论】:

      【解决方案2】:
      loadComplete: function (data) {
          var $this = $(this),
              datatype = $this.getGridParam('datatype');
      
          if (datatype === "xml" || datatype === "json") {
              setTimeout(function () {
                  $this.trigger("reloadGrid");
              }, 100);
          }
      }
      

      这只会执行一次。在这个线程上喜欢这个。 Default sorting of jqgrid on particular field when grid loads

      【讨论】:

        猜你喜欢
        • 2011-08-02
        • 1970-01-01
        • 2020-09-04
        • 1970-01-01
        • 2020-09-11
        • 2012-02-22
        • 2018-07-11
        • 2020-02-19
        • 1970-01-01
        相关资源
        最近更新 更多