【问题标题】:jsTree is not renderedjsTree 未呈现
【发布时间】:2011-12-16 11:59:13
【问题描述】:

谁能看到我的语法错误? jsTree 就是不会渲染。

加上 jquery 1.7 中的一个奇怪错误:

未捕获的错误:语法错误,无法识别的表达式:#

var data = [
    {
    "data": "Basics",
    "state": "closed",
    // omit `attr` if not needed; the `attr` object gets passed to the jQuery `attr` function
    "attr": { "id": "1234", "some-other-attribute": "attribute_value" },
    "children": [{
        "data": "login",
        "state": "closed",
        "children": [
        {
            "data": "results",
            "state": "closed",
            "attr": { "id": "node-123" }
        }]
    }]
}];

$(function () {
    $("#jstree").jstree({
        "json_data": {

            //initial - demo only, usually takes json from the controller
            //static data, or function(node, mappingBeforeRequestToserver)
            "data": data,


            //If both data and ajax are set the initial tree is rendered from the data string. 
            //When opening a closed node (that has no loaded children) an AJAX request is made.
            "ajax": {

                //data: mappingBeforeRequestToserver-function(node about to be open or -1).  `this` will be the tree instance) 
                //url: function(node about to be open as a paramater or -1) retuns the ajax URL (like /get_children/node_2).
                //The error and success functions- modifiying the results from the server before populating the tree  



                type: "POST",
                async: true,
                "url": "/echo/json/",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                cache: false,
                success: function (msg) {
                    return msg;
                },
                error: function () {
                    // TODO process error
                }
            },
//          "xsl": "flat",
//          "override_ui": "true",
//          "real_checkboxes": "true",
            "plugins": ["themes", "json_data", "ui"]
        }
        // 1) if using the UI plugin bind to select_node
    }).bind("select_node.jstree", function (event, data) {
            // `data.rslt.obj` is the jquery extended node that was clicked
            alert(data.rslt.obj.attr("id"));
        })
});

【问题讨论】:

  • 错误信息会很有帮助。

标签: javascript jquery asp.net jstree


【解决方案1】:

找到它:一个额外的}

“插件”:[“主题”,“json_data”,“ui”]

【讨论】:

    【解决方案2】:

    这看起来可能是个问题:

    "children": ["login",
        {
            "data": "results",
            "state": "closed",
            "attr": {
                "id": "node-123"
            }
         }
    ]
    

    上面的"login" 看起来是错误的。 jsTree documentation 表示 "children" 属性应该是“子节点对象数组”; "login" String 的存在违反了这一点。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-09
    • 2018-10-09
    • 1970-01-01
    相关资源
    最近更新 更多