Reputation: 93
I'm receiving a response from my SOAP web-service in XML using Javascript SOAP Client. I Parsed all the data i wanted from it to a string.
[{ZNA_COD:'111',ZNA_DESIG:'Blabla'},{ZNA_COD:'11',ZNA_DESIG:'Blabla'},{ZNA_COD:'1',ZNA_DESIG:'Blabla'},{ZNA_COD:'2',ZNA_DESIG:'Blabla'},{ZNA_COD:'11111',ZNA_DESIG:'Blabla'}]
How can i store it in Sencha Touch 2? What is the best approach?
Upvotes: 0
Views: 800
Reputation: 1914
I've used ST1.1 and only just starting on ST2.
I guess it depends on what you are trying to do. If your data is always being pulled from the live source, you could just use the Ext.data.Store and define a reader. In your case, it would have a type of xml.
Ext.define('ZNA', {
extend: 'Ext.data.Model',
config: {
fields: [
{name: 'ZNA_COD', type: 'string'},
{name: 'ZNA_DESIG', type: 'string'}
]
},
});
var store = Ext.create('Ext.data.Store', {
model: 'ZNA',
proxy: {
type: 'ajax',
url : 'www.your-service-url.com',
reader: {
type: 'xml',
record: 'ZNA'
}
}
});
store.load();
If you use this process, it automatically pull the data into your store when you call the load method. Or you could set autoLoad on it.
If you have the data already on your device and are happy with how you got it there. You could then just create a new instance of your model and populate it with your values. Then you would save it to your store.
var instance = Ext.create('ZNA', {
ZNA_COD:'111',
ZNA_DESIG:'Blabla'
});
store.add(instance);
You may need to check the syntax, I may have some ST1.1 stuff floating in there.
Upvotes: 1
Reputation: 6365
First of all you should parse your data to a valid JSON string, for eg.: {data: [your data here]}
Provided that you manage to do this, then the remaning task is very simple which consists of 2 steps:
Ext.decode
to parse your string to a JSON objectresult.data
is now your result array. Iterating through them and adding them to Ext.data.Store
is very simple as I think it's not needed to write down here, isn't it?Upvotes: 0