Jstree не присваивает идентификатор элементу li - PullRequest
0 голосов
/ 27 января 2012

У меня есть экземпляр Jstree.Это AJAX с JSON.

Вот как я создаю дерево.

        $("#tree").jstree({
            "plugins" : ["themes", "json_data", "ui"],
            "json_data" : {
                "ajax" : {
                    "type": 'GET',
                    "url": function (node) {
                        var nodeId = "";
                        var url = ""
                        if (node == -1)
                        {
                            //first url called is static
                            url = "myUrl";
                        }
                        else
                        {
                           //click on a node "li", get the id, append it to the url.
                           nodeId = node.attr('id');
                           url = "myUrl" + nodeId;
                        }

                        return url;
                    },
                    "success": function (new_data) {
                       //get the data topNode out of the json object
                       new_data = new_data.topNode;

                       return new_data;
                    }
                }
            },

        }); 

Вот вывод.

<div id="tree" class="jstree-classic jstree jstree-0 jstree-focused jstree-default">
    <ul>
        <li class="jstree-closed jstree-last">
            <ins class="jstree-icon">&nbsp;</ins>
            <a class="" href="#">Item 1</a> 
        </li>
    </ul>
</div>

Однако, когда дерево отображаетсяэлемент

не имеет идентификатора.Должен автоматически добавляться к .Чего мне не хватает?

Ответы [ 2 ]

1 голос
/ 27 января 2012

Если ниже ваши данные, возвращенные из ajax-вызова, вам нужно переместить "id":"1" в атрибуты раздел

{"topNode":{"data":"Item 1",
            "children":[],
            "state":"closed",
            "id":"1",
            "attributes":{"class":"editContainerL‌​ink","href":"#"}
           }
}

так бы выглядело

{"topNode":{"data":"Item 1",
            "children":[],
            "state":"closed",
            "id":"1",
            "attributes":{"class":"editContainerL‌​ink",
                          "href":"#",
                          "id":"1"
                          }
           }
}
0 голосов
/ 15 февраля 2013

просто измените атрибуты на attr, и идентификатор появится в узле 'a'.Мне также нужен идентификатор в узле 'li', но до сих пор мои попытки с метаданными не были успешными.

// the `metadata` property will be saved using the jQuery `data` function on the `li` node
"metadata" : "a string, array, object, etc",

from: http://www.jstree.com/documentation/json_data

...