2011-10-24 23 views
0

this question類似,我無法讓我的DataView實際顯示數據。我試圖重新調整我的商店,但我想我錯過了一些東西。下面是我到目前爲止有:如何爲Ext.DataView構造數據?

應用程序,模型,商店

Ext.regApplication({ 
    name: 'TestApp', 
    launch: function() { 
     this.viewport = new TestApp.views.Viewport(); 
    } 
}); 

TestApp.models.StoreMe = Ext.regModel('TestApp.models.StoreMe', { 
    fields: [ 
     'id', 
     'name', 
     'age' 
    ] 
}); 

TestApp.stores.storeMe = new Ext.data.Store({ 
    model: 'TestApp.models.StoreMe', 
    proxy: { 
     type: 'ajax', 
     url: 'data.json', 
     reader: { 
      type: 'json' 
     } 
    }, 
    autoLoad: true 
}); 

視口和數據視圖

TestApp.views.Viewport = Ext.extend(Ext.Panel, { 
    fullscreen: true, 
    layout: 'card', 
    items: [ 
     { 
      id: 'dataView', 
      xtype: 'dataview', 
      store: TestApp.stores.storeMe, 
      itemSelector: 'div.dataViewItem', 
      emptyText: 'NO DATA', 
      tpl: '<tpl for "."><div class="dataViewItem">ID: {id}<br />Name: {name}<br />Age: {age}</div></tpl>' 
     } 
    ] 
}); 

JSON

[ 
    { 
     "id": "1", 
     "name": "sam", 
     "age": "4" 
    }, 
    { 
     "id": "2", 
     "name": "jack", 
     "age": "3" 
    }, 
    { 
     "id": "3", 
     "name": "danny", 
     "age": "12" 
    } 
] 

有什麼建議嗎?所有與此類似的其他問題都使用Ext.JsonStore,但Sencha API文檔說這樣做。

UPDATE

該店工作的罰款。下面是TestApp.stores.storeMe.data樣子:

Ext.util.MixedCollection 
    ... 
    items: Array[3] 
     0: c 
      data: Object 
       age: "4" 
       id: "1" 
       name: "sam" 
     1: c 
     2: c 
     length: 3 
     __proto__: Array[0] 
    keys: Array[3] 
    length: 3 
    ... 
+0

更好的問題:我如何得到一個Ext.DataView只顯示一個項目?硬模式:過濾商店不起作用。 – Yoshokatana

+0

TestApp.stores.storeMe.data的輸出是什麼? –

+0

它給了我三件物品。我將它添加到主要問題中。 – Yoshokatana

回答

1

我是個白癡。我:

tpl: '<tpl for "."><div class="dataViewItem">ID: {id}<br />Name: {name}<br />Age: {age}</div></tpl>' 

我需要:

tpl: '<tpl for=".">...</tpl>' 
+0

祝賀解決方案。如果可以,請確保將您的答案標記爲「已接受」,以便其他人可以從您的成功中學習。乾杯〜 –

1

看來你沒有與所謂的「數據」根JSON結構?嘗試更改您的JSON到:

{ 
    "data": [ { 
     "id": "1", 
     "name": "sam", 
     "age": "4" 
    }, { 
     "id": "2", 
     "name": "jack", 
     "age": "3" 
    }, { 
     "id": "3", 
     "name": "danny", 
     "age": "12" 
    } ] 
} 

並在您的閱讀器中放入一行 - 根:'data'。

+0

仍然無法使用。我認爲這可能與商店中存在多個對象有關。但是,當我添加一個過濾器時,它仍然無法修復它。 – Yoshokatana

+0

@Yoshokatana,那不太可能。你確定你的商店包含數據嗎?嘗試TestApp.stores.storeMe.data。 –