Hello,
I've been developing some application using Sencha Touch 2 and I've encountered a little problem - I got a model:
Code:
Ext.define('STI.model.NotecaseMenu', { extend: 'Ext.data.Model',
config: {
fields: [
{ name: 'fund', type: 'string' },
{ name: 'subfund', type: 'string' },
{ name: 'balance', type: 'float' },
{ name: 'registryNumber', type: 'string' },
{ name: 'productType', type: 'string' },
{ name: 'currency', type: 'string' },
{ name: 'distributor', type: 'string' },
{ name: 'openDate', type: 'string' },
{ name: 'registryState', type: 'string' },
{ name: 'unitValue', type: 'float' },
{ name: 'loss', type: 'float' },
{ name: 'bankAccount', type: 'string' }
]
}
});
,
and a store:
Code:
Ext.define('STI.store.NotecaseMenuStore', { extend: 'Ext.data.Store',
config: {
model: 'STI.model.NotecaseMenu',
storeId: 'notecaseMenuStore',
data: [
{ fund: 'Company FIO', subfund: 'AKCJA', balance: 5000.0, registryNumber: '700-025-689', productType: 'rejestr zwykły', currency: 'PLN', distributor: 'ProService AT', openDate: '2006-11-14', registryState: '975,773 j.u.', unitValue: 329.00, loss: 222466.42, bankAccount: '26 1140 1010 7020 0002 0002 0000' },
{ fund: 'Company FIO', subfund: 'AKCJA', balance: 1544.0, registryNumber: '700-895-623', productType: 'rejestr zwykły', currency: 'PLN', distributor: 'ProService AT', openDate: '2006-11-14', registryState: '5,53 j.u.', unitValue: 329.00, loss: 222466.42, bankAccount: '26 1140 1010 7020 0002 0002 0000' },
{ fund: 'Company FIO', subfund: 'WAGA', balance: 2045.0, registryNumber: '400-012-300', productType: 'rejestr zwykły', currency: 'PLN', distributor: 'ProService AT', openDate: '2006-11-14', registryState: '75,72 j.u.', unitValue: 329.00, loss: 222466.42, bankAccount: '26 1140 1010 7020 0002 0002 0000' },
{ fund: 'Company FIO', subfund: 'WAGA', balance: 4288.0, registryNumber: '400-047-950', productType: 'rejestr zwykły', currency: 'PLN', distributor: 'ProService AT', openDate: '2006-11-14', registryState: '773,554 j.u.', unitValue: 329.00, loss: 22246.642, bankAccount: '26 1140 1010 7020 0002 0002 0000' },
{ fund: 'Company FIO', subfund: 'WAGA', balance: 1234.5, registryNumber: '400-047-950', productType: 'rejestr zwykły', currency: 'PLN', distributor: 'ProService AT', openDate: '2006-11-14', registryState: '773,554 j.u.', unitValue: 329.00, loss: 22246.642, bankAccount: '26 1140 1010 7020 0002 0002 0000' }
]
}
});
Now, I want to write an utility function that will sum all the balance fields from the store and return a result. I was trying to write a function, and then get a store with Ext.getStore('notecaseMenuStore'), but it says it's undefined.
Code:
notecaseValue = function(){
var store = Ext.getStore('notecaseMenuStore');
var count = store.getCount();
var sum = 0;
for(i = 0; i < count; i++)
{
sum += store.getAt(i).data.balance;
}
return sum;
}
Where did I go wrong? Is there another way around? Should I define that utility class somehow?
Regards,
lovemyway