-
25 Apr 2012 11:17 AM #1
ArrayStore data problem in 4.1
ArrayStore data problem in 4.1
I've got my Model, which defines fields ['firstName', 'lastName', 'age'], and my ArrayStore that sets the data as [['Bob', 'Johnson',23], ['Alice', 'Smith', 55]], and I'm getting objects that look like:
{ firstName: 'Johnson', lastName: '23', age: undefined }
{ firstName: 'Smith', lastName: '55', age: undefined }
There's clearly some index problem. In a loop somewhere.
-
25 Apr 2012 12:16 PM #2
See if the following works for you:
Regards,Code:Ext.create('Ext.data.Store', { storeId:'myStore', fields:['firstName', 'lastName', 'age'], data:{'items':[ { 'firstName': 'Bob', 'lastName':'Johnson', 'age':23 }, { 'firstName': 'Alice', 'lastName':'Smith', 'age':55 } ]}, proxy: { type: 'memory', reader: { type: 'json', root: 'items' } } }); Ext.create('Ext.grid.Panel', { title: 'Names', store: Ext.data.StoreManager.lookup('myStore'), columns: [ { header: 'firstName', dataIndex: 'firstName' }, { header: 'lastName', dataIndex: 'lastName', flex: 1 }, { header: 'age', dataIndex: 'age', type: 'int' } ], height: 200, width: 400, renderTo: Ext.getBody() });
Scott.
-
25 Apr 2012 1:12 PM #3
Yes, that works, and I can't get it to break by switching it to an array reader or an ArrayStore.
I'll have to examine my complex scenario – which was working in 4.0 – a little further.
Thanks.
-
26 Apr 2012 10:38 AM #4
REPLICATED!
REPLICATED!
I figured it out. Not the fix, but how to replicate it. It only breaks when the model in the store does not directly extend Ext.data.Model, but extends an intermediary type.
You can see it in action here.
Code included below.
Code:Ext.define('myapp.data.Model', { extend:'Ext.data.Model', constructor:function (config) { this.callParent(arguments); } }); Ext.define('myapp.model.Person', { extend:'myapp.data.Model', alternateClassName:['Person'], idProperty:'name', fields:[ { name:'firstName', type:'string' }, { name:'lastName', type:'string' }, { name:'age', type:'int' } ] }); Ext.define('myapp.store.Person', { extend:'Ext.data.ArrayStore', model:'myapp.model.Person', storeId:'Person', data:[ ['Alex', 'Bridgestone', 45], ['Brenda', 'Carson', 34], ['Dan', 'Epstein', 34] ] } ); Ext.create('myapp.store.Person'); Ext.onReady(function () { Ext.create('Ext.container.Viewport', { layout:'fit', items:[ { xtype:'grid', title:'Awesome People', store:'Person', columns:[ { header:'First Name', dataIndex:'firstName' }, { header:'Last Name', dataIndex:'lastName', flex:1 }, { header:'Age', dataIndex:'age' } ] } ] }); });
Wait! Looks like we don't have enough information to add this to bug database. Please follow this template bug format.


Reply With Quote