2016-12-06 4 views
0

変数があり、$('#tree').jstree()に渡したいと思います。JSONを変数としてjsTreeに渡す

が試み:

$('#tree').jstree({ 
    plugins: ["checkbox", "types"], 
    "types": { 
     "file": { 
      "icon": "jstree-file" 
     } 
    }, 
    'core': { 
     'data': mdata.data 

    } 
}); 
//------------------------------ 
$('#tree').jstree({ 
    plugins: ["checkbox", "types"], 
    "types": { 
     "file": { 
      "icon": "jstree-file" 
     } 
    }, 
    'core': { 
     'data': JSON.stringify(mdata.data) 

    } 
}); 
//------------------------------ 
$('#tree').jstree(mdata.data) 

マイJSON変数(mdata.data)は、すでにJSON.parse()によって解析されます。私はjsonlint.comとそれが有効であることを検証しました。ここでは、次のとおりです。コンソールの

[{ 
    "soslist": [{ 
     "code_intext": "utf-8", 
     "count_of_pages": 2, 
     "count_of_records": 7, 
     "curobj": "1", 
     "obj": "1", 
     "page": 1 
    }, { 
     "code_intext": "utf-8", 
     "count_of_pages": 2, 
     "count_of_records": 7, 
     "curobj": "1", 
     "obj": "1", 
     "page": 1 
    }], 
    "system": [{ 
     "count_of_pages": 2, 
     "count_of_records": 7, 
     "curobj": "1", 
     "page": 1 
    }] 
}] 

mdata.data

が、それも可能ですかjsTreeがidparent_idなどの具体的なJSON構造とかがありますか?

答えて

0

jsTreeには特定のJSON構造が必要です。そのdocumentationから:

// Expected format of the node (there are no required fields) 
{ 
    id   : "string" // will be autogenerated if omitted 
    text  : "string" // node text 
    icon  : "string" // string for custom 
    state  : { 
    opened : boolean // is the node open 
    disabled : boolean // is the node disabled 
    selected : boolean // is the node selected 
    }, 
    children : [] // array of strings or objects 
    li_attr  : {} // attributes for the generated LI node 
    a_attr  : {} // attributes for the generated A node 
} 

あなたのオブジェクトは、完全に異なるフォーマットであり、それは動作しません。

関連する問題