Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.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
Jquery 仅在jqgrid的第一次加载时运行方法_Jquery_Jqgrid - Fatal编程技术网

Jquery 仅在jqgrid的第一次加载时运行方法

Jquery 仅在jqgrid的第一次加载时运行方法,jquery,jqgrid,Jquery,Jqgrid,当我加载jqgrid时,我在loadcomplete部分以以下方式填充过滤器工具栏选择框: $(".ui-search-toolbar").find("select").each(function (index, value) { getDropdowndata($(this).attr('NAME')); }); 问题是每次重新加载网格时,该代码都会运行。这会导致当我通过示例单击多个页面时,选择框填充多个值 我想要的是只在第一次加载网格时运行此代码。最简单的解决方案是使用布尔变量并检

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

$(".ui-search-toolbar").find("select").each(function (index, value) {
    getDropdowndata($(this).attr('NAME'));
});
问题是每次重新加载网格时,该代码都会运行。这会导致当我通过示例单击多个页面时,选择框填充多个值


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

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

var isPopulated = false;

...

function onLoadComplete(){
   if(!isPopulated){
      //your code here
      isPopulated = true;
   }
}
这将只执行一次。我喜欢这条线

loadComplete: function (data) {
    var $this = $(this),
        datatype = $this.getGridParam('datatype');

    if (datatype === "xml" || datatype === "json") {
        setTimeout(function () {
            $this.trigger("reloadGrid");
        }, 100);
    }
}