kendo treeview复选框-父节点检查-更改每个复选框上的事件 [英] kendo treeview checkbox - parent node check - change event on every checkbox
问题描述
我有一个具有父级和子级节点的 2级Kendo UI树视图. 当我检查父节点时,将自动检查所有子节点(包括父节点).
I have a 2-level Kendo UI Treeview with parent and children nodes. When I check a parent node, all children nodes (including parent) are automatically checked.
现在我要发送一个具有当前树选择状态的事件. 问题是当我尝试在 dataSource.change 方法中执行此操作时,因为它分别在每个复选框选择上触发(1个父节点+ 3个子节点= 4个更改事件).代码如下所示:
Now I want to send an event with current tree selection state. The problem is when I try to do it in dataSource.change method because it fires on every checkbox selection separately (1 parent node + 3 children nodes = 4 change events). This is what the code looks like:
treeView.data("kendoTreeView").dataSource.bind("change", function() {
alert('event fired!');
});
我创建了一个工作示例此处
I've created a working example here
是否要附加另一个事件,以便在更新所有复选框后仅触发一个事件? 或者也许有一种方法可以将所有这些更改"事件分组并只触发一个?
Is there another event to attach to to have only one event fired after all checkboxes are updated? Or maybe there is a way to group all those 'change' events and fire just one instead?
推荐答案
我已经结束了此解决方案:
I've ended with this solution:
tree.data("kendoTreeView").dataSource.bind("change", function() {
treeView = tree.data("kendoTreeView");
checkedNodes = [];
checkedNodeIds(treeView.dataSource.view(), checkedNodes);
if (!timeoutSet) {
setTimeout(fireCheckboxChangeOnce, 50);//fires only one event when parent checkbox checks all the children
timeoutSet = true;
}
});
只有第一个事件会创建对函数的延迟调用(使用 setTimeout()). 其余所有更改"事件仅修改 checkedNodes 参数.
Only the first event creates a delayed call to function (using setTimeout()). All the remaining "change" events only modify the checkedNodes parameter.
fireCheckboxChangeOnce 函数还会清除 timeoutSet 标志.
这篇关于kendo treeview复选框-父节点检查-更改每个复选框上的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!