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