0

私は次のコードを持っています:

new Ext.DataView({
    store: new Ext.data.JsonStore({
        url: 'request/getAssetsJSON',
        baseParams: {
            _id: this.request._id
        },
        root: 'results',
        fields: [ 'attachment', 'id', 'name', 'property', 'type' ],
        autoLoad: true
    }),
    emptyText: 'No images to display',
    tpl: new Ext.XTemplate(
        '<tpl for=".">',
            '<div class="thumb-wrap" id="{name}">',
            '<div class="thumb"><p>Test</p><img height="45" src="request/getAsset?id={id}&attachment={attachment}" title="{name}"></div>',
            '<span class="x-editable">{name}</span></div>',
        '</tpl>',
        '<div class="x-clear"></div>'
    )
})

request/getAssetsJSONによって送信されるJSONは次のとおりです。

[{"attachment":"img1.png","id":"4dc90e2a6ba440e37601d5d074011e2e","name":"img1"},   
{"attachment":"img2.png","id":"4dc90e2a6ba440e37601d5d074011e2e","name":"img2"},
{"attachment":"img3.png","id":"4dc90e2a6ba440e37601d5d074011e2e","name":"img3"}]

私の問題は、DataViewが最後の画像(img3.png)のみを表示し、request/getAssetへのGETリクエストが1つしかないことです。

ExtJSがテンプレートを反復処理する方法、またはデータをロードする方法に問題があると思いますが、ここでは途方に暮れています。

誰かアイデアはありますか?

4

1 に答える 1

0

すべてのアイテムに同じID「id」:「4dc90e2a6ba440e37601d5d074011e2e」があります。サーバー側でjson応答を変更するか、このデータのモデルを作成してidProperty:'_id'(デフォルトのidProperty:'id')を設定できます。

Ext.define('YouModel', {
    extend: 'Ext.data.Model',

    config: {
        idProperty : '_id',
        fields: [
            {name: 'id',          type: 'auto'},

            {name : 'attachment',      type : 'string'},
            {name : 'name',  type : 'string'}
        ]

    }
});

new Ext.DataView({
    store: new Ext.data.JsonStore({
        url: 'request/getAssetsJSON',
        baseParams: {
            _id: this.request._id
        },
        root: 'results',
        model: 'YourModel',
        autoLoad: true
    }),
  ....
})
于 2012-07-18T15:13:30.217 に答える