分享個combotree允許多選的時候onSelect事件(通常是點擊“+”號時)會重復觸發onCheck事件的蠢解決辦法是:
1.弄一個全局變量:
var loading = false; //表示在觸發combotree各種事件時是否遍歷樹;
2.設置onSelect時不做任何操作:
$("input[name='XXXXX']").combotree({
。。。
onSelect: function(node) {
return;
},
。。。
});
3.設置onBeforeLoad時loading為true:
$("input[name='XXXXX']").combotree({
。。。
onBeforeLoad: function(row) {
loading = true;
。。。
},
。。。
});
4.設置onLoadSuccess時loading為false:
$("input[name='XXXXX']").combotree({
。。。
onLoadSuccess: function (row, data) {
loading = false;
。。。
},
。。。
});
5.onCheck時判斷如果為true,表示代碼試圖遍歷樹,則不執行對所勾選數據的處理;
$("input[name='XXXXX']").combotree({
。。。
onCheck: function (data, checked) {
if (loading) {
return;
}
if (checked == true) {}
。。。
},
。。。
});
大家如果還有其他更好解決辦法,歡迎提供。。
