Jquery Jstree复选框事件捕获 [英] Jquery Jstree checkbox events capture

查看:1338
本文介绍了Jquery Jstree复选框事件捕获的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对jQuery和jstree完全陌生。我使用jstree和使用xml填充数据。但是想要捕获每个节点的事件,无论是否被检查以及它们的Id。我尝试使用jstree的插件API像 change_state() check_node() select_node 但它不工作。



感谢...

div class =h2_lin>解决方案

我喜欢jstree插件,但它没有很好的文档,也没有构建符合说,jquery ui标准的插件开发。我已经使用1.0rc2来完成你想要做的事情。



你必须绑定loaded事件之前你实例化jstree,所以我猜与change_state事件相同。另一件要注意的是,change_state不仅仅是一个复选框的更改。例如,它也会在您展开节点时触发(但由于某种原因不会崩溃)。也就是说,我做一些kludgey检查change_state处理程序,尝试和过滤掉不必要的事件从复选框更改。点击处理程序的最小代码是

  $(#treeElement)。bind(change_state.jstree,function e,d){
var tagName = d.args [0] .tagName;
var refreshing = d.inst.data.core.refreshing;
if((tagName ==A || tagName ==INS)&&
(refreshing!= true&& refreshing!=undefined)){
//如果复选框或其文本被点击,
//这不是由于刷新或初始加载,请运行此代码。。
}
});

您点击的元素为 d.rslt 并且您可以通过 d.inst.get_checked()获取单击的元素或 d.inst.get_checked(d.rslt) 用于包含已选中的子节点的对象。使用jquery的.each函数来处理节点。


I am totally new to jQuery and jstree. I am using jstree and populating the data using xml. But would like to capture event for each node whether checked or not along with their Ids. I tried using jstree's plugins API like change_state(),check_node() or select_node() but it's not working. Also I would like to get all selected nodes data in an array for further processing..Can anyone help?

Thanks...

解决方案

I like the jstree plugin but it's not well documented, nor is it built to conform to say, jquery ui standards of plugin development. I have used 1.0rc2 to accomplish what you're trying to do.

You have to bind the "loaded" event before you instantiate the jstree so I'm guessing it's the same with the "change_state" event. The other thing to watch out for is that "change_state" is more than just a change due to a check box. For instance it will also fire when you expand a node (but not collapse, for some reason). That said, I do some kludgey checking in the "change_state" handler to try and filter out unwanted events from the checkbox change. The minimum code for tapping the handler is

$("#treeElement").bind("change_state.jstree", function (e, d) {
    var tagName = d.args[0].tagName;
    var refreshing = d.inst.data.core.refreshing;
    if ((tagName == "A" || tagName == "INS") &&
      (refreshing != true && refreshing != "undefined")) {
    //if a checkbox or it's text was clicked, 
    //and this is not due to a refresh or initial load, run this code . . .
    }
});

Your clicked element is then d.rslt and you can get checked items with d.inst.get_checked() for just the element clicked, or d.inst.get_checked(d.rslt) for an object containing the sub nodes that are checked. Use jquery's .each function to process the nodes.

这篇关于Jquery Jstree复选框事件捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆