簡體   English   中英

如何從文本中獲取子節點?

[英]how to get child node from text?

您能告訴我如何從文本中獲取子節點嗎?實際上,當用戶單擊該節點並獲得該子節點的使用價值時,

alert("node_children: " + data.node.children);

但是,現在我有一些按鈕“獲取子項”,當我僅使用文本單擊“ a”和“ b”的“子項”按鈕時,我需要獲取靜態文本“ a”和“ b”嗎? http://jsfiddle.net/fuu94/12/

$('#home').click(function () 
{
    var rootChildren = $('#tree').find('ul > li');
    $(rootChildren).each(function(index, item)
    {
        console.log(item.id); 
    });
});

我能收到我的不是短信嗎?

更新的小提琴

更改

 $('#child').click(function () {
         alert('child of b');

    });

     $('#child').click(function () {
alert($('#tree').jstree(true).get_node('b').children);
    });

你的意思是這樣嗎?

 $('#child').click(function (e) {
     alert($('#tree').jstree('get_selected')[0])
});

我是否缺少某些東西,或者這可能像使用一樣簡單

 console.log(item.text());

代替

console.log(item.id);

根據API可以使用

$.jstree._reference('#tree').get_text(node);

暫無
暫無

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

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