PDA

View Full Version : How can i loaddata in store from a url?



chenzhaoplus
29 Mar 2012, 5:45 PM
my code is:


Ext.Ajax.request({
url : 'http://localhost:8080/admin-web/jsonservice/foodEmbranchmentService.json',
method : 'POST',
jsonData : {
jsonrpc : "2.0",
id : 10,
method : "findAll"
},
success : function(result, request) {
var resultStr = result.responseText;
var jsonObj = Ext.decode(resultStr);
var jsonStr = Ext.encode(jsonObj);
store.loadData(jsonObj.result.resultList);
},
failure : function(form, action) {
Ext.MessageBox.alert("JSON Test", "JSON Failed?");
}
});





Ext.define('MyApp.stores.CanyindanweiStore', {
extend : 'Ext.data.Store',
singleton : true,
requires : ['MyApp.models.CanyindanweiModel'],


model : 'MyApp.models.CanyindanweiModel',
remoteSort : false,
storeId : 'canyindanweiStore'
});

i don't use proxy but Ext.ajax.requst in store because proxy can not post jsonData to url.If i loaddata in store,the data can show in gridpanel,the problem is when i select a record,i can not get a record from selectionmodel.

vietits
29 Mar 2012, 6:26 PM
Why don't you use ajax proxy with extraParams config.


Ext.define('MyApp.stores.CanyindanweiStore', {
extend : 'Ext.data.Store',
singleton : true,
requires : ['MyApp.models.CanyindanweiModel'],
model : 'MyApp.models.CanyindanweiModel',
remoteSort : false,
storeId : 'canyindanweiStore',
proxy: {
type: 'ajax',
url: 'http://localhost:8080/admin-web/jsonservice/foodEmbranchmentService.json',
method: 'POST',
extraParams: {
jsonrpc : "2.0",
id : 10,
method : "findAll"
},
reader: {
type: 'json',
root: 'root'
}
}
});

chenzhaoplus
29 Mar 2012, 6:33 PM
i tried,it doesn't work. i just checked my code.i find my problem is i spelled the wrong name in formpanel.so i can't see the data in formpanel.the problem is cleared. thank you!