PDA

View Full Version : Problem updating the Store



bevara.siva
20 Mar 2014, 5:31 AM
Hi,

We are using "Sencha Architect 3" and "Ext JS 4.2.x" framework.
I have created a store in the Sencha Architect and added 2 fields.
I have added an array in the data section as below



Ext.define('ViewSample.store.Destination', {
extend: 'Ext.data.Store',


requires: [
'Ext.data.Field'
],


constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
autoLoad: true,
storeId: 'Destination',
data: [
{
name: 'PDF File',
value: '1'
},
{
name: 'XML File',
value: '2'
}
],
fields: [
{
name: 'name'
},
{
name: 'value'
}
]
}, cfg)]);
}
});
.

I am trying add records to this store on a button click using the following code.



var store = Ext.getStore('Destination');
store.add({name: 'siva File', value: '1'});


After this if I see the count it showing as record is added.
But when see the store the record is not added.

Please help!!

Regards,
SivaPrasad.B

scottmartin
20 Mar 2014, 6:09 AM
I see 3 records:

Paste the code here and run:
https://fiddle.sencha.com/#home



Ext.define('ViewSample.store.Destination', {
extend: 'Ext.data.Store',

requires: [
'Ext.data.Field'
],

constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
autoLoad: true,
storeId: 'Destination',
data: [
{
name: 'PDF File',
value: '1'
},
{
name: 'XML File',
value: '2'
}
],
fields: [
{
name: 'name'
},
{
name: 'value'
}
]
}, cfg)]);
}
});


Ext.onReady(function(){
var store = Ext.create('ViewSample.store.Destination');

store.on('add', function(store){
console.log(store.getCount()); // 3
console.log(store.data.items); // [constructor, constructor, constructor]
});

store.add({name: 'siva File', value: '1'});
});