jsTree 使用替代 JSON 格式和 AJAX 自定义 <li>

jsTree customize <li> using the alternative JSON format along with AJAX

我正在使用替代 JSON 格式以及 AJAX 来加载树中的数据。现在有一个新问题,要求我在

  • 标签的末尾添加一个新元素。

    我创建了示例 URL 来显示我当前正在做的事情。 Tree crated using alternative JSON format along with AJAX

    以及新 LI 应该如何出现 Tree created using hard coded HTML but shows how the LI should look like

    我想如果我使用 HTML 数据我应该能够做到这一点,但是由于项目已经使用 JSON 格式,所以在我开始制作之前我需要做很多改变这个重大变化我只是想检查是否可以使用 JSON 和 AJAX 格式。

  • 所以我得到了 Ivan 的回答 - Answer

    简而言之,在 src 文件夹中有 misc.js,其中有问号插件,这是我想要做的最好的例子。

    我根据需要调整了它的代码,这是新代码。

    (function ($, undefined) {
        "use strict";
        var span = document.createElement('span');
        span.className = 'glyphicons glyphicons-comments flip jstree-comment'
    
        $.jstree.defaults.commenticon = $.noop;
        $.jstree.plugins.commenticon = function (options, parent) {
            this.bind = function () {
                parent.bind.call(this);            
            };
            this.teardown = function () {
                if (this.settings.commenticon) {
                    this.element.find(".jstree-comment").remove();
                }
                parent.teardown.call(this);
            };
            this.redraw_node = function (obj, deep, callback, force_draw) {
                var addCommentIcon = true;
                var data = this.get_node(obj).data;
                //....Code for deciding whether comment icon is needed or not based on "data"
                var li = parent.redraw_node.call(this, obj, deep, callback, force_draw);
                if (li && addCommentIcon) {
                    var tmp = span.cloneNode(true);
                    tmp.id = li.id + "_commenticon";
                    var $a = $("a", li);
                    $a.append(tmp);
                }
                return li;
            };
        };
    })(jQuery);