且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将Json作为变量加载到jsTree中

更新时间:2022-06-02 22:02:02

$.jstree.defaults.core.themes.responsive = true;
$('#tree').jstree({
    plugins: ["checkbox", "types"],
    "types": {
        "file": {
            "icon": "jstree-file"
        }
    },
    'core': {
        'data': {
            'url': function(node) {
                return 'nodes.json'
            },
            'data': function(node) {
                return {
                    'id': node.id
                };
            }
        }
    }
});

我刚刚更加密切地遵循了Ivan的JSTree API.他的API非常出色,密切关注它会为您省去很多麻烦.另外,我相信自己的json有一个预告逗号,并且它是无效的,因此我也必须修复它.我使用JSON验证程序进行了测试.

I just followed Ivan's JSTree API more closely. His API is fantastic and following it closely will save you a lot of headache. ALSO, my json had a trailer comma I beleive and was invalid, so I had to fix that as well. I tested using a json validator.