Reputation: 303
Is there a way to make the data store to create a model containing all the fields retrieved from the server?
Lets say we have on the server side the object:
User : {
name: "...",
phone: "...",
Address: {
street: "...",
country: "...",
},
...
...
}
And we use the following store to load this user:
var myStore = Ext.create('Ext.data.Store', {
proxy: {
type: 'ajax',
url: '...',
reader: {
type: 'json',
root: 'users'
}
},
fields :[name, phone],
autoLoad: true
});
Is there a way to config the fields inside the data store to retrieve all the fields from the user without a specific mapping like the example (name, phone)? I mean, can I put something like ** in the fields attribute that will say to the data store, map all the fields retrieved as they are, and the result will be a store with the user's name, phone and address?
Thanks.
Upvotes: 2
Views: 1575
Reputation: 195
yes it is possible there is proper code snipet which will help you
var fields = [];
Ext.each(me.dataFromServer, function (record) {
fields.push({
name: record.fieldName
});
});
var myModel = Ext.define('myModelName',{
extend: 'Ext.data.Model',
idProperty: 'id', //some field
fields: fields
});
and our store looks like this
me.store = Ext.create('yourStore',{
model: myModel
});
and thic code is located in initComponent:
Your store:
extend: 'Ext.data.Store',
//model: null,
without model.
Upvotes: 2