0

Ext.data.JsonReader を使用して Ext.data.JsonStore モデルをマッピングしているときに、sencha で問題に直面しています。

サーバーからの Json 応答 (サーバー モデル):

{"rows":[{"id":1,"firstname":"Bill"},{"id": 2,"firstname":"Ben"}]}

Json ストアで使用されるモデル:

Ext.regModel( 'mycabinet', {
fields: [ 
{ name : 'DeviceId', type: 'int' },
'CabinetName']
});

json リーダー コード:

var iccDeviceReader = new Ext.data.JsonReader({
// metadata configuration options:
idProperty: 'id',
root: 'rows',
fields: [
{name: 'CabinetName', mapping: 'firstname'},
{name:'DeviceId',mapping:'id'}
]
});

json ストア コード:

app.iccDS = new Ext.data.JsonStore( {
model : 'mycabinet',
sorters  : 'CabinetName',
getGroupString : function(record) { return record.get('CabinetName')[0]; },
proxy    : {
type: 'ajax',
url : '/icc/js/data.js',
reader:iccDeviceReader
},
autoLoad: true
} );

「mycabinet」モデルに「サーバー モデル」が追加されることを期待しています。ただし、マッピングは行われません。成功せずに convert を使用してみました(name:'DeviceId',mapping:'id',convert: function(v){return v.id;})

どんな助けでも大歓迎です。ありがとう

4

2 に答える 2

0

次のコードは私の問題を解決しました...

Ext.regModel( 'mycabinet', {
fields: [ 
{ name : 'DeviceId', type: 'int',mapping:'id' },
{name: 'CabinetName', mapping: 'firstname'}]
});

app.iccDS = new Ext.data.JsonStore( {
model : 'mycabinet',
sorters  : 'CabinetName',
getGroupString : function(record) { return record.get('CabinetName')[0]; },
proxy    : {
type: 'ajax',
url : '/icc/js/data.js'
},
autoLoad: true
} );

私はもうjsonReaderを使用していません。

于 2011-10-06T06:01:11.697 に答える
0

リーダーから「fields」オプションを削除し、モデル構成で「CabinetName」を {name: 'CabinetName', mapping: 'firstname'} に変更ます。また、idPropertyもモデル構成に含める必要があります。

于 2011-10-05T18:09:28.543 に答える