如何将数据关联到jstree中的节点? [英] How to associate a data to a node in jstree?

查看:68
本文介绍了如何将数据关联到jstree中的节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$("#ifTree").jstree({
            "plugins" : ["themes","html_data","ui","crrm"], 
            "themes" : {
                    "theme" : "apple",
                    "dots" : true,
                    "icons" : false
            }           
    });

    $("#createIf_c").click(function () { 
        $("#ifTree").jstree("create",null,"inside",  { "data" :{ title:"if",value:"expression"} },
                function() {}, true);
    });
$("#display").click(function(){
            var a = $.jstree._focused().get_selected();
            alert(a.attr("value"));
    });

在上面的代码中,我创建了一个jstree,并单击ID为#createIf_c的按钮,我添加了一个标题为"if"的节点,但是由于我希望有更多数据与此节点相关联,因此我添加了更多创建节点时对其赋予属性.接下来,当我尝试访问此关联数据(此处为值")时,我将收到警报未定义".那么,是否存在将数据与节点关联的其他方法? jstree是访问节点关联数据的另一种方法?请帮助....

In this above code I have created a jstree and upon click of a button with id #createIf_c I am adding a node with title "if" but as I want some more data to be associated with this node , I have added more attributes to it while creating the node. Next when I am trying to access this associated data, here "value" then I am getting the alert 'undefined'. So is there a different way for associating data with a node? or a different way of accessing the associated data of a node is jstree?..please help....

推荐答案

最简单的方法就像将属性添加到html元素即

The simplest way to do this is just like adding an attribute to an html element i.e.,

    var node = $.jstree._focused().get_selected(); //get the selected node or which ever you want the data to be associated with
    node.attr("expression","xyz"); //add an attribute (name,value) here, name-expression and value-xyz

这篇关于如何将数据关联到jstree中的节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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