-
16 Nov 2011 7:32 AM #1
Unanswered: Data Store
Unanswered: Data Store
Hey..
I just started developing with sencha touch.
I have a small problem while working with Store..I am not able to get data as i need.Its a simple data.
Below is how i create the store..
Ext.regModel('Alert', {
fields: [
'AlertType', 'AlertName','AlertDescription']
});
Ext.AlertData = new Ext.data.Store({
id:'AlertStoreId',
model:'Alert',
sorters: [{
property: 'AlertType'
}],
autoLoad : true,
proxy:{
type:'ajax',
url:'my url is here.',
reader:{
type:'xml',
record:'Alert'
}
}
}
);
What i want is all the values for 'AlertType' field in an array.
Please post complete implementation(code).Because i have tried many things like getGroupedString..and Filters, setting grouped property etc...etc..Nothing seems to work.
My store is populated properly with data...
-
16 Nov 2011 2:06 PM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,107
- Vote Rating
- 453
- Answers
- 3157
For Sencha Touch 2, you should define your Model and create your store this way:
For your Store, I wouldn't use the Ext namespace. You should have one for your namespace. You can go through your Store using the each method:Code:Ext.define('Alert', { extend : 'Ext.data.Model', fields: ['AlertType', 'AlertName','AlertDescription'] }); Ext.AlertData = Ext.create('Ext.data.Store', { model:'Alert', sorters: [{ property: 'AlertType' }], autoLoad : true, proxy:{ type:'ajax', url:'my url is here.', reader:{ type:'xml', record:'Alert' } } });
Code:var values = []; store.each(function(rec) { values.push(rec.get('AlertType')); });Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
17 Nov 2011 3:42 AM #3
The snippet does not seem to work.I am still getting an empty array.
Below is not working
var values = [];
Ext.AlertData.each(function(rec) {
values.push(rec.get('AlertType'));
console.log(rec.get('AlertType'));
});
console.log("values",values);
Below is not working
var values = [];
Ext.AlertData.on('load', function () {
Ext.AlertData.data.each(function(rec) {
values.push(rec.get('AlertType'));
})});
console.log("values",values);
Below is working: The data gets printed in the console.
Ext.AlertData.on('load', function () {
Ext.AlertData.data.each(function(rec) {
console.log(rec.get('AlertType'));
})});
Please provide a solution..
-
17 Nov 2011 6:02 AM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,107
- Vote Rating
- 453
- Answers
- 3157
This is working for me 100%:
Code:var store = Ext.create('Ext.data.ArrayStore', { fields: [ {name: 'company'}, {name: 'price', type: 'float'}, {name: 'change', type: 'float'}, {name: 'pctChange', type: 'float'}, {name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'} ], proxy : { type : 'ajax', url : 'data.php', reader : { type : 'json', root : 'data' } } }); var values = []; store.on('load', function() { store.each(function(rec) { values.push(rec.get('company')); }); console.log(values); //is an array with all companies }); store.load();Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
20 Nov 2011 10:43 PM #5
Hi..
Hi..
Is this happening because I am doing an HTTP connection and the retrieving the data from a URL..Issue of asynchronous call?
-
21 Nov 2011 7:39 AM #6Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,107
- Vote Rating
- 453
- Answers
- 3157
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
21 Nov 2011 6:22 PM #7
But how do I know that..when it has loaded...
-
22 Nov 2011 7:20 AM #8Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,107
- Vote Rating
- 453
- Answers
- 3157
orCode:store.load({ callback: function(records, operation, success) { //store has been loaded } });
Code:store.on('load', function(store, recs, success) { //store has been loaded, single : true will remove this listener after first time executing }, store, { single : true });Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.


Reply With Quote