我想做一個樹,從JSON本地文件加載信息,代碼,我有樹加載父節點,但子節點不加載,是缺少的東西在我的代碼?ExtJS加載本地json文件到樹面板
型號:
Ext.define('modeloCapa', {
extend: 'Ext.data.Model',
fields: ['nombre', 'capas', 'capa']
});
商店:
var treeStore = Ext.create('Ext.data.TreeStore', {
model: 'modeloCapa',
proxy: {
type: 'ajax',
url: "jsontestq.json",
reader: {
type : 'json',
root : 'Result'
}
}
});
樹面板:
Ext.create('Ext.tree.Panel', {
title: 'Prueba',
width: 500,
height: 550,
store: treeStore,
rootVisible: false,
renderTo: Ext.getBody(),
columns: [{
xtype: 'treecolumn',
text: 'Col1',
flex: 2,
sortable: true,
dataIndex: 'nombre'
}]
});
JSON文件:
{"Result":[{
"nombre":"Transporte Marítimo Fluvial ",
"id":74,
\t "capas":[{
\t \t "id":268,
\t \t "capa":{
\t \t \t "id":268,
\t \t \t "titulo":"puerto_p_25k",
\t \t \t "url":"http:\/\/172.17.2.157:8080\/geoserver\/sigtierras\/wms",
\t \t \t "nombre":"puerto_p_25k",
\t \t \t "metadato":"",
\t \t \t "wfs":false
\t \t }
\t }]
},{
"nombre":"Entidades Territoriales y Unidades Admin ",
"id":65,
\t "capas":[{
\t \t "id":239,
\t \t "capa":{
\t \t \t "id":239,
\t \t \t "titulo":"limite_25k",
\t \t \t "url":"http:\/\/172.17.2.157:8080\/geoserver\/sigtierras\/wms",
\t \t \t "nombre":"limite_25k",
\t \t \t "metadato":"",
\t \t \t "wfs":false
\t \t }
\t },{
\t \t "id":319,
\t \t "capa":{
\t \t \t "id":319,
\t \t \t "titulo":"administrativo_p_25k",
\t \t \t "url":"http:\/\/172.17.2.157:8080\/geoserver\/sigtierras\/wms",
\t \t \t "nombre":"administrativo_p_25k",
\t \t \t "metadato":"",
\t \t \t "wfs":false
\t \t }
\t }]
},{
"nombre":"Instalaciones Construcciones para el Transporte ",
"id":67,
\t "capas":[{
\t \t "id":269,
\t \t "capa":{
\t \t "id":269,
\t \t "titulo":"red_alta_tension_25k",
\t \t "url":"http:\/\/172.17.2.157:8080\/geoserver\/sigtierras\/wms",
\t \t "nombre":"red_alta_tension_25k",
\t \t "metadato":"",
\t \t "wfs":false
\t \t }
\t },{
\t \t "id":260,
\t \t "capa":{
\t \t \t "id":260,
\t \t \t "titulo":"peaje_25k",
\t \t \t "url":"http:\/\/172.17.2.157:8080\/geoserver\/sigtierras\/wms",
\t \t \t "nombre":"peaje_25k",
\t \t \t "metadato":"",
\t \t \t "wfs":false
\t \t }
\t },{
\t \t "id":275,
\t \t "capa":{
\t \t \t "id":275,
\t \t \t "titulo":"torre_25k",
\t \t \t "url":"http:\/\/172.17.2.157:8080\/geoserver\/sigtierras\/wms",
\t \t \t "nombre":"torre_25k",
\t \t \t "metadato":"",
\t \t \t "wfs":false
\t \t }
\t },{
\t \t "id":266,
\t \t "capa":{
\t \t "id":266,
\t \t "titulo":"puente_l_25k",
\t \t "url":"http:\/\/172.17.2.157:8080\/geoserver\/sigtierras\/wms",
\t \t "nombre":"puente_l_25k",
\t \t "metadato":"",
\t \t "wfs":false
\t \t }
\t },{
\t \t "id":267,
\t \t "capa":{
\t \t \t "id":267,
\t \t \t "titulo":"puente_p_25k",
\t \t \t "url":"http:\/\/172.17.2.157:8080\/geoserver\/sigtierras\/wms",
\t \t \t "nombre":"puente_p_25k",
\t \t \t "metadato":"",
\t \t \t "wfs":false
\t \t }
\t },{
\t \t "id":259,
\t \t "capa":{
\t \t \t "id":259,
\t \t \t "titulo":"paso_nivel_25k",
\t \t \t "url":"http:\/\/172.17.2.157:8080\/geoserver\/sigtierras\/wms",
\t \t \t "nombre":"paso_nivel_25k",
\t \t \t "metadato":"",
\t \t \t "wfs":false
\t \t }
\t },{ \t
\t \t "id":223,
\t \t "capa":{
\t \t \t "id":223,
\t \t \t "titulo":"antena_25k",
\t \t \t "url":"http:\/\/172.17.2.157:8080\/geoserver\/sigtierras\/wms",
\t \t \t "nombre":"antena_25k",
\t \t \t "metadato":"",
\t \t \t "wfs":false
\t \t }
\t },{ \t
\t \t "id":273,
\t \t "capa":{
\t \t \t "id":273,
\t \t \t "titulo":"terminal_p_25k",
\t \t \t "url":"http:\/\/172.17.2.157:8080\/geoserver\/sigtierras\/wms",
\t \t \t "nombre":"terminal_p_25k",
\t \t \t "metadato":"",
\t \t \t "wfs":false
\t \t }
\t },{ \t
\t \t "id":265,
\t \t "capa":{
\t \t \t "id":265,
\t \t \t "titulo":"poste_25k",
\t \t \t "url":"http:\/\/172.17.2.157:8080\/geoserver\/sigtierras\/wms",
\t \t \t "nombre":"poste_25k",
\t \t \t "metadato":"",
\t \t \t "wfs":false
\t \t }
\t },{
\t \t "id":276,
\t \t "capa":{
\t \t \t "id":276,
\t \t \t "titulo":"tuberia_25k",
\t \t \t "url":"http:\/\/172.17.2.157:8080\/geoserver\/sigtierras\/wms",
\t \t \t "nombre":"tuberia_25k",
\t \t \t "metadato":"",
\t \t \t "wfs":false
\t \t }
\t }]}]
}
謝謝你的建議。
也許您的JSON文件不提供正確的屬性。子元素必須放置在「子」子數組中。看看這裏:http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.tree.Panel。 – Tyr
謝謝,有什麼辦法可以用這個文件做樹? – davids182009
看到我的回答下面 – Tyr