0

我已经创建了 jsTree,如下所示。

$("#treeViewDiv").jstree({
"json_data" : {
    "data":[
        {
            "data" : {
                "title" : "Search engines",
                "state": "closed"
            },
            "children" :[
                {
                    "data":{
                    "title" : "Yahoo"
                    "state": "closed"
                }
                }
            ]
        },
        {
            "data" : {
                "title" : " Networking sites ",
                "state": "closed"
            }
        }
    ]
},  
"plugins" : [ "themes", "json_data", "ui" ]
});

现在我想获取所选节点的标题。我尝试了以下但它给了我“父节点的标题+子节点的标题”的结果。请帮忙。

bind("select_node.jstree", function(e, data){
    var selectedObj = data.rslt.obj;
    selectedObj.text()
});
4

4 回答 4

1

普拉文的解决方案:

$('.jstree-clicked').text();
于 2012-10-03T10:01:18.357 回答
1
<script type="text/javascript" >
   $(function () {
       $("#demo1")
           .jstree({
               // the `plugins` array allows you to configure the active plugins on this instance
               "plugins": ["themes", "html_data", "ui", "crrm", "hotkeys", "json_data"],
               "core": {
                   "initially_open": ["phtml_1"]
               }
           })


          // EVENTS
          // each instance triggers its own events - to process those listen on the container
          // all events are in the `.jstree` namespace
          // so listen for `function_name`.`jstree` - you can function names from the docs
          .bind("loaded.jstree", function (event, data) {
              // Every Work You like do in loaded jstree ...
          })

         .bind("select_node.jstree", function (event, data) {
             //`data.rslt.obj` is the jquery extended node that was clicked   
             alert("Selected node text :" + data.inst.get_text(data.rslt.obj));
             alert("Selected node Tag a text:" + data.rslt.obj.find('a').first().text());
             alert("Selected node Tag a title:" + data.rslt.obj.find('a').attr("title"));
             alert("Selected node Tag a href Address" + data.rslt.obj.children("a").attr("href"));
             alert("Selected node Parent ID = " + data.inst._get_parent(data.rslt.obj).attr("id"));

             var parent = data.inst._get_parent(data.rslt.obj);
             alert("Selected node Parent Text = " + parent.find('a').first().text());
             alert("Selected node Parent Tag a title:" + parent.find('a').attr("title"));

         }
       );

   });
</script>
于 2015-06-29T14:55:46.347 回答
0
var divselected = $('#treeViewDiv').jstree('get_selected');
于 2013-10-11T19:42:04.370 回答
0
alert("Selected node Tag a title:" + data.rslt.obj.find('a').attr("title"));
于 2015-06-29T16:21:00.437 回答