kendo treeview checkbox - parent node check - change event on every checkbox

北慕城南 提交于 2020-01-05 08:02:33

问题


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.

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?


回答1:


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;
    }
});

Only the first event creates a delayed call to function (using setTimeout()). All the remaining "change" events only modify the checkedNodes parameter.

fireCheckboxChangeOnce function also clears the timeoutSet flag.



来源:https://stackoverflow.com/questions/15972838/kendo-treeview-checkbox-parent-node-check-change-event-on-every-checkbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!