PDA

View Full Version : change params value while loading store



sinaalizadeh
23 Mar 2015, 4:01 AM
I have a store which I need to call it multiple times with different parameter value. parameter values are in an array and I need to call the store with array order. How can I change params value inside load method?



var i = -1;
me.getMyStore().on('beforeload',function(store, options) {
i++;
});
me.getMyStore().load({
params: {id: ids[i]},
scope: this,
callback: function(records, operation, success) {
// I need to increase value of i by 1
}
})


I call a beforeload event before to increase the i's value but it doesn't work

slemmon
13 Apr 2015, 12:37 PM
Hi,

The issue you're seeing is that the beforeload event handler is fired prior to the load() call's params being set on its proxy operation. Probably the better way to go about incrementing the id in the load call is something like:

l6b

f.baron
13 Apr 2015, 11:58 PM
You can send also the index as parameter to use it in the callback recursive call:



var ids = ['a', 'b', 'c'],
myStore = Ext.create('Ext.data.Store', {
fields: [],
proxy: {
type: 'ajax',
url: 'data1.json'
}
}),

callback = function(records, operation) {
var next = operation.params.i + 1;
if (next < ids.length) {
this.load({
params: {
id: ids[next],
i: next
},
callback: callback
});
}
};


myStore.load({
params: {
id: ids[0],
i: 0
},
callback: callback
});