2016-12-06 2 views
0

Ich habe eine Variable und ich möchte es an übergeben.Weitergabe von JSON als Variable an jsTree

Versuchte:

$('#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) 

Meine JSON Variable (mdata.data) wird bereits von JSON.parse() analysiert. Ich habe es über jsonlint.com validiert und validiert. Hier ist sie:

[{ 
    "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 in der Konsole:

Ist es überhaupt möglich oder jsTree benötigen spezifische JSON Struktur und Material wie id und parent_id?

Antwort

0

jsTree benötigt eine spezifische JSON-Struktur. Aus ihrer 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 
} 

Ihre Aufgabe besteht darin, in einem ganz anderen Format, so dass es nicht funktionieren wird.

Verwandte Themen