Ext JS 4 store load callback Ext JS 4 store load callback json json

Ext JS 4 store load callback


First of all a load for a store expects an array, and second you set the root for the proxy wrong. since there is no d.data object in your json. Simple fix will be to encode your json data as an array with one element, and the tag for that array to be "data" ...

{"d":[{"__type":"Urlopy.services.UserPreference","userID":"12445","admin":true}]}

and just set the root to d

reader : {    type : 'json',    root : 'd'}

After this on the callback you'll have an array of records with one element that you can simply access with index 0

callback : function(records, options, success) {    console.log(records[0].data.userID +" " + records[0].data.admin);}

EDIT

Other method not involving stores

Do a simple ajax request like:

Ext.Ajax.request({            url: 'services/UserPreferences.asmx/Get',            params: {/*if you want any extra params to be sent*/},            scope: this,            success: function (result) {                var response = Ext.decode(result.responseText);                //this is for your initial json                alert(response.d.userID);            },            failure: function (result) {                alert('something failed')                }        });

I don't know what you do with the data, but for example you can load it into a form, and for the update method then you will have the submit option for the form. which can be configured with the url where to send the data.