PDA

View Full Version : Loading data to HttpProxy from the JSON



karantir
6 Sep 2007, 7:06 AM
Hi.

Originally I had combobox which store data was driven by SimpleStore and when I needed to reload this combo contents I simply call loadData() method and pass appropriate JSON (I've just fetched via AJAX request). Recently I had changed SimpleStore to HttpProxy and now I want to reload my combo, but don't know how. HttpProxy class don't support loadData(). I've already tried to use load() method with specific parameters (to fetch required JSON directly) but have no luck. So the question is -- how to reload combobox contents which store is driven by HttpProxy?

Here is my original code snippet (with incorrect in this context loadData()). I need to reload accesses combo, when modules combo will change:


...
item_data = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url: '/ajax.php?module=admin.sitemap&action=get&id_item=' + item.id}),
reader: new Ext.data.JsonReader({},['id_access','id_module','moduleParams','itemName','urlPart','state']),
remoteSort: false
});
item_props = new Ext.form.Form({
...
});
...
item_data.on('load', function() {
var access_data = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url: '/ajax.php'}),
reader: new Ext.data.ArrayReader({},['id_access','accessName']),
remoteSort: false
});
var modules_data = new Ext.data.SimpleStore({
fields: ['id_module', 'moduleName'],
data: Ext.admin.modules,
});
...
access_data.on('load', function() {
...
var modules = new Ext.form.ComboBox({
fieldLabel: 'Module',
hiddenName: 'id_module',
value: modules_value,
triggerAction: 'all',
emptyText: '',
store: modules_data,
valueField:'id_module',
displayField:'moduleName',
mode: 'local',
width: item_props_field_w
});
var accesses = new Ext.form.ComboBox({
fieldLabel: 'Access',
hiddenName: 'id_access',
value: access_value,
triggerAction: 'all',
emptyText: '',
store: access_data,
valueField:'id_access',
displayField:'accessName',
mode: 'local',
width: item_props_field_w,
disabled: (modules_value == 0) ? true : false
});
...
item_props.fieldset(
{legend: "Item properties"},
itemName,
urlPart,
states,
modules,
accesses,
moduleParams
);
item_props.render('cbody');
modules.on('select', function(){
Cthulhu.showProgress('Waiting for server...');
ajax = new Ext.data.Connection;
ajax.request({
url: '/ajax.php',
method: 'POST',
params: {
module: 'admin.sitemap',
action: 'get_accesses',
id_module: modules.getValue()
},
callback: function(options, success, response) {
if (success) {
data = eval('(' + response.responseText + ')');
if (accesses.disabled) accesses.enable();
if (moduleParams.disabled) moduleParams.enable();
if (data) {accesses.store.loadData(data);}
}
Cthulhu.hideProgress();
}
});
});
Cthulhu.hideProgress();
});
access_data.load({
method: 'POST',
params: {
module: 'admin.sitemap',
action: 'get_accesses',
id_module: id_module
}
});
});
...
item_data.load();


Thanks for advance!

Animal
6 Sep 2007, 7:33 AM
It's the Store which is reloaded.

http://extjs.com/deploy/ext-1.1.1/docs/output/Ext.data.Store.html#reload