1

我使用 aciTree 查看列表项。排序后,我想列出所有父母相同级别的孩子,但我无法得到它们。它们只是 HTML 节点 li 标签。如何返回 json 节点。

                    case 'sorted':
                        var pr = api.parent(item);
                        var allChilds =  api.children();
                        var arrChilds = api.children(pr, false, false);  

                        $.each(arrChilds, function(id,child) {
                              console.log(api.itemData(child));   // here error  
                         });   

                        console.log(api.itemData(item)); 

                        break;
4

3 回答 3

1

您可以尝试以下代码:

    var api = $("#Tree").aciTree("api");
    var allChild = api.children(null, true, true);// you can change null to any node , now it get the whole tree

    allChild.each(function (index, item) {
        var $item = $(item);
        var data = api.itemData($item);// itemData return json object for the selected item.
    });
于 2015-11-09T15:42:54.083 回答
0

itemData 需要一个项目对象,而 children 返回<li>项目列表。尝试这个;

    $.each(arrChilds, function(id,child) {
      var item = api.itemFrom(child);
      console.log(api.itemData(item));   // here error  
    }); 
于 2015-02-12T01:19:38.867 回答
0
var allChild = api.children (item, true, true);

如果您想要根目录中的所有子项,您将获得 item 的所有子项,并且 item 为 null

于 2015-07-06T02:16:45.583 回答