PDA

View Full Version : How to add field data to a store



emm
24 Sep 2010, 7:22 AM
Hi,
I use localstorage to save data from a twitter account. I use this model to read a twitter timeline :


Ext.regModel('tweetMod', {
fields: [
{name:'idid', type:'string', mapping: 'id'}, //id
{name:'text', type:'auto'}, //message
{name:'created_at', type: 'date'},
{name:'user', type:'auto'}
]

});


and then this model to save the data in localstorage



Ext.regModel('tweetModFav', {
fields: [
{name:'idid', type:'string'}, //id
{name:'text', type:'auto'}, //message
{name:'created_at', type: 'date',
encode: function(value) {
return +(value);
},
decode: function(value) {
return new Date(value);
},
},
{name:'user', type:'auto'}
]

});


Now I want to add data to each record : to do that I can add a {name:'newdata', type:'string'} to the model for localstorage.
But then, how can I add data to each record of the store I use for reading twitter stream?

Thanks for your help!
Best,
emm

evant
26 Sep 2010, 7:49 PM
In the same way, it's just that the value will be undefined when you load it from the remote source.

emm
28 Sep 2010, 1:15 AM
Thank you for your answer evant.
OK I can add a new field that will be undefined.
What's the method to put some value instead of undefined for each records of a store?
Thank you!
emm

evant
28 Sep 2010, 1:38 AM
You could use a convert function on the field. http://dev.sencha.com/deploy/touch/docs/?class=Ext.data.Field&member=convert