簡體   English   中英

如何在jsTree中獲取所選節點的標題?

[英]How to get title of selected node in jsTree?

我創建了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()
});

普拉文的解決方案:

$('.jstree-clicked').text();
<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>
var divselected = $('#treeViewDiv').jstree('get_selected');
alert("Selected node Tag a title:" + data.rslt.obj.find('a').attr("title"));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM