2011-10-24 10 views
0

this questionと同様に、データビューを実際に表示することができません。私は自分の店を再構築しようとしましたが、私は何か不足していると思います。ここで私はこれまで持っているものです: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 
}); 

ビューポートとのDataView

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

ストアが正常に動作しています。

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

それは私に3つの項目を与えます。私は主な質問にそれを加えました。 – 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構造を持っていないようだ。ここでTestApp.stores.storeMe.dataは次のようになりますか?お使いのリーダーに - 「データ」: - ルート

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

とラインを置く:あなたにJSONを変更してみてください。

+0

まだ動作しません。私はそれが店に複数のオブジェクトがあるという事実と関係があるかもしれないと思う。しかし、フィルタを追加すると、まだ修正されません。 @ Yoshokatana、 – Yoshokatana

+0

それはそうではありません。あなたの店にデータが含まれていますか? TestApp.stores.storeMe.dataを試してください。 –

関連する問題