2012-02-23 95 views
0

我想使JSON在Extjs樹中工作,這將有助於簡化編輯。extjs樹模式的JSON結構

{ 
name: '.', 

department: [{ 
    name:'Basic Ext Layouts', 
    expanded: false, 
    Maths:[{ 
     name:'Absolute', 
     id:'absolute', 
     leaf:true, 
    },{ 
     name:'Accordion', 
     id:'accordion', 
     leaf:true 
    },{ 
     name:'Anchor', 
     id:'anchor', 
     leaf:true 
    },{ 
     name:'Border', 
     id:'border', 
     leaf:true 
    },{ 
     name:'Card (TabPanel)', 
     id:'card-tabs', 
     leaf:true 
    },{ 
     name:'Card (Wizard)', 
     id:'card-wizard', 
     leaf:true 
    },{ 
     name:'Column', 
     id:'column', 
     leaf:true 
    },{ 
     name:'Fit', 
     id:'fit', 
     leaf:true 
    },{ 
     name:'Table', 
     id:'table', 
     leaf:true 
    },{ 
     name:'vBox', 
     id:'vbox', 
     leaf:true 
    },{ 
     name:'hBox', 
     id:'hbox', 
     leaf:true 
    }] 
},{ 
    name:'Custom Layouts', 
    bilology:[{ 
     name:'Center', 
     id:'center', 
     leaf:true, 
    },{ 
    name:'Custom Layouts 2', 
    zoology:[{ 
     name:'Center', 
     id:'left', 
     leaf:true 
    }]},{ 
    name:'Custom Layouts 3', 
    botony:[{ 
     name:'Center', 
     id:'right', 
     leaf:true 
    }]}] 
},{ 
    name:'Combination Examples', 
    English:[{ 
     name:'Absolute Layout Form', 
     id:'abs-form', 
     leaf:true 
    },{ 
     name:'Tabs with Nested Layouts', 
     id:'tabs-nested-layouts', 
     leaf:true 
    }] 
}] 
} 

請幫

+0

你檢查ExtJS的文檔? http://docs.sencha.com/ext-js/3-4/#!/api/Ext.tree.TreePanel – 2012-02-23 07:44:25

+0

是的,我做了很多研發,但沒有得到結果。我需要js代碼,它將以這種格式創建樹。我想給出一個deoartment的名字,而不僅僅是一個「children:」節點。 – Dhananjay 2012-02-23 07:47:43

回答

2

這裏是你的JSON看起來應該像樹面板爲例:

{ text: 'Maths', id: 'mathDept', children: [ 
     { text:'X1', id: 'x1', leaf: true }, 
     { text:'X2', id: 'x2', leaf: true} 
    ] 
}, 
{ text: 'Biology', id: 'bioDept', children: [ 
     { text: 'Y1', id: 'y1', leaf: true}, 
     { text: 'Y2', id: 'y2', leaf: true} 
    ] 
}, 
{ text: 'English', id: 'engDept', children: [ 
     { text: 'Z1', id: 'z1', leaf: true}, 
     { text: 'Z2', id: 'z2', leaf: true}, 
     { text: 'Z3', id: 'z3', leaf: true}    
    ] 
} 
+0

謝謝,但我想重命名子節點爲部門特定節點,如: {text:'Maths',id:'mathDept',Maths:[ {text:'X1',id:'x1',leaf :'}},{}} {text:'X2',id:'x2',leaf:true} ] }, {text:'Biology',id:'bioDept',Biology:[{text:'Y1 ',id:'y1',leaf:true}, {text:'Y2',id:'y2',leaf:true} ] }, {text:'English',id:'engDept',英文:[ {text:'Z1',id:'z1',leaf:true}, {text:'Z2',id:'z2',leaf:true}, {text:'Z3',id :'z3',葉:t rue} ] } – Dhananjay 2012-02-23 09:31:06

+0

我認爲它不是不可能的。 @Abdel如何寫是唯一的可能性。 – devOp 2012-02-23 11:42:44

+0

我想給json中的每個節點賦予不同的子名稱,如何實現它是js文件。 { 名:」 ' 部門:[{ 名:' 基本分機佈局, 擴大:假的, 數學:[{ 名: '絕對', ID: '絕對', 葉:真, },{ 名稱: '手風琴', ID: '手風琴', 葉:真 },{ 名稱: '錨', ID: '錨', 葉:真 } ,{ name:'Border', id:'border', leaf:true } – Dhananjay 2012-02-23 13:03:51