Hi all,
I am calling an ASP.NET web service that returns JSON data with two roots, using Ext.Ajax.request and i am handling the returned response successfully.
What i need to do is to save this JSON data to a new Ext.Store.
I know that i can call the web service directly from the store, but in my case the returned JSON data have multiple roots so i can save each root into a store.
This is my code:
Code:
Ext.regModel('GendersModel', {
fields:[
{name:'GenderID'},
{name:'GenderDescription'},
{name:'GenderPicture'}
]
});
Ext.regModel('CompositionModel', {
fields:[
{name:'CompositionID'},
{name:'CompositionDescription'}
]
});
var GendersStore = new Ext.data.Store({
id: 'GendersStore',
model: 'GendersModel',
listeners: {
beforeload: function(myStore, options) {
},
load: function(myStore, records, options) {
console.log('Genders' + myStore.getCount());
},
exception: function(misc) {
}
}
});
var CompositionStore = new Ext.data.Store({
id: 'CompositionStore',
model: 'CompositionModel',
listeners: {
beforeload: function(myStore, options) {
},
load: function(myStore, records, options) {
console.log('Composition' + myStore.getCount());
},
exception: function(misc) {
}
}
});
Ext.Ajax.request({
url:myURL,
method: 'GET',
jsonData: { "Alert": {} },
headers: { 'Content-Type': 'application/json;charset=utf-8' },
success: function (response, opts) {
var json = Ext.decode(response.responseText);
console.log(json); //the returned json is valid.
//here i want to save the json to Genders store and Composition store.
//i have tried this, but it is not working:
GendersStore.loadData(json);
CompositionStore.loadData(json);
},
failure: function (response, opts) {
alert('Error calling server.');
}
});
I need to make it in this way because i want to make only one call to the web service, get the data, fill two stores, i dont want to make multiple calls.
This is my JSON data:
Code:
"{"list1":[{"GenderID":1,"GenderDescription":"Gender1","GenderPicture":"/ipadcatalog/pictures/bundle.png"},{"GenderID":2,"GenderDescription":"Gender2","GenderPicture":"/ipadcatalog/pictures/bundle.png"},{"GenderID":3,"GenderDescription":"Gender3","GenderPicture":"/ipadcatalog/pictures/bundle.png"}],"list2":[{"CompositionID":1,"CompositionDescription":"Nylon"},{"CompositionID":2,"CompositionDescription":"Coton"},{"CompositionID":3,"CompositionDescription":"Leather"}]}"
Please i need help with this issue.
Thank you in advance.