2

EXTJS4TreePanelでJSONデータを表示する作業をしています。しかし、私のツリーにはデータが表示されていません。どこが間違っているのか教えてください。以下に私のコードを投稿させてください:

パーツを見る:ツリーパネルがあります

xtype: 'treepanel', 
title: 'Standard Geographies',
height: 250,
width: 310,
store: 'Data',  
border: 1,          
displayField: 'name',
useArrows: true,
rootVisible: true,
multiSelect: true,
preventHeader: true,                                            
renderTo: Ext.getBody(),

columns: [{
    xtype: 'treecolumn',
text: 'Standard Geographies',
flex: 1,
sortable: false,
//renderer : change,
dataIndex: 'name'
}], 

モデルパーツ:jsonデータの使用

Ext.define('TA.model.TAModel', {
    extend: 'Ext.data.Model',
    fields: ['name','typeId'],
//fields: ['abbr','type'],['name','typeId']


    proxy: {
        type: 'ajax',
        url : 'data/StandardGeoTree.json',
        actionMethods: {
            read: 'POST'
        },
        reader: {
            type: 'json',
            root: 'geographyOptions' 
        },
    }   
 });

ストアパート:ストアパートですべてが大丈夫だといいのですが

Ext.define('TA.store.Data', {
//extend: 'Ext.data.Store',
//model: 'TA.model.TAModel',

extend: 'Ext.data.TreeStore',
model: 'TA.model.TAModel', 
autoSync: true,
autoLoad: true,     
listeners: {
    load:function(){
        console.log('Schemes Data store loaded');
    }
},      
proxy: {
    type: 'ajax',
    //url : 'data/StandardGeoTree.json',
    api: {
        //read: 'data/StandardGeo.json',
        read: 'data/StandardGeoTree.json',
        //update: 'data/updateTradeArea.json'
    },
    reader: {
        type: 'json',
        root: 'root',
        successProperty: 'success',
        idProperty : 'typeId'
    }
},  
root : {
    text: 'Root',
    id: 'typeId',
    expanded : true,
    loaded : true,
    children: []
}
});

JSON

{
"success": true,
"root" : [
    {   
        "name": "001-USA", 
        "typeId" : "1",

        "children":[        
            {"name": "USA", "typeId" : "1", "leaf":"true"},
            {"name": "State", "typeId" : "2", "leaf":"true"},
            {"name": "DMA", "typeId" : "3", "leaf":"true"},
            {"name": "CSA", "typeId" : "4", "leaf":"true"},

            ]
    }
]
}   
4

3 に答える 3

1

ツリーコンポーネントのストア構成は、実際にはそれほど複雑である必要はありません。たとえば、以下の単純なストア宣言で十分です。

var treestore = Ext.create('Ext.data.TreeStore', {
    proxy: {
        type: 'ajax',
        url: 'data/StandardGeoTree.json'
    }
});

次に、ツリー構成セットstore: treestorerootVisible: false

最後に、ストアはjsonが次の形式で応答することを期待しています。

[{
    "text": "To Do", 
    "cls": "folder",
    "expanded": true,
    "children": [{
        "text": "Go jogging",
        "leaf": true
    },{
        "text": "Take a nap",
        "leaf": true
    },{
        "text": "Climb Everest",
        "leaf": true
    }]
}]
于 2012-11-29T03:31:10.747 に答える
0

解決策として機能したものはありません。それで、私は私の問題を解決する私の見解で以下のコード部分を書かなければなりませんでした。以下のコード部分を貼り付けています。

    var treeStore = Ext.StoreManager.lookup('Data');
    treeStore.load();

しかし、ストアが自動的に読み込まれるようにしたいのです。ストアを自動的にロードするための解決策があれば教えてください。

于 2012-11-29T07:21:53.983 に答える
0

JSONでは、rootプロパティは子に類似している必要があります。つまり、「ルート」または「子」のいずれかですが、両方ではありません。完全な説明については、この質問を参照してください。

だからあなたが固執することを考えると:

reader: {
    type: 'json',
    root: 'root',
    successProperty: 'success',
    idProperty : 'typeId'
}

JSONは次のようになります。

{
"success": true,
"root" : [
    {   
        "name": "001-USA", 
        "typeId" : "1",

        "root":[        
            {"name": "USA", "typeId" : "1", "leaf":"true"},
            {"name": "State", "typeId" : "2", "leaf":"true"},
            {"name": "DMA", "typeId" : "3", "leaf":"true"},
            {"name": "CSA", "typeId" : "4", "leaf":"true"},

            ]
    }
]
} 
于 2012-11-28T15:35:39.160 に答える