开发者

Detect checkbox change in jstree

开发者 https://www.devze.com 2023-03-20 06:54 出处:网络
I am using the latest jstree commit from github with the checkbox plugin as a part of my form. I am using the tree with the \"real_checkboxes\" attribute.

I am using the latest jstree commit from github with the checkbox plugin as a part of my form. I am using the tree with the "real_checkboxes" attribute.

Everything is fine except the checkbox plugin does not actually add any changed property attribute to the hidden field and nor does it seem to have a external function that will allow me to hook in to create custom functionality.

Is it possible for me to understand and listen for when a checkbox is either ticked or unticked?

Thanks,

UPDATE: after doing some experimenting I was able to over ride the default functionality of the check and uncheck methods using:

$.jstree._instance.prototype.check_node = function(node){ alert("here"); }

However it isn't very clean and it does overr开发者_开发技巧ide the whole method.

Is there:

a) a cleaner way to do it? b) a way to just do a callback on the function rather than replacing the whole damn thing?

Thanks again,


@Noctyrn

Yes I did that originally but then I looked through the docs a lot more closely and found this:

$(".js_tree_'.$this->attribute.' div").bind("check_node.jstree", function(){});

But yes your function does the same :). But since mine is right to the jsTree docs Ima mark my answer as the right one. Also that function allows for different trees on the same page to have different binds so it is better overall :).

Thanks for the help :),


This is actually less clean but at least it gets the job done:

var check_node_func = $.jstree._instance.prototype.check_node;
$.jstree._instance.prototype.check_node = function(node) {
    check_node_func.apply(this, arguments);
    alert("here");
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号