问题
On a sencha-touch, here's is my store declaration
Ext.regStore('newsStore', {
model: 'News',
autoLoad: true,
proxy: {
type: 'ajax',
url: '../news/list.form?format=json',
reader: {
type: 'json',
root: ''
}
},
});
How can I modify params? I tried
params:{ format: 'json'}
But its doesn't work!
回答1:
Store declaration
new Ext.data.Store({
model:'prj.models.ContactInfo',
storeId:'contactInfoId',
proxy:{
type:'ajax',
url:'/GetContactInfoByID',
reader:{
type:'json'
},
extraParams:{
format:'json'
},
listeners:{
exception:function(proxy, response, orientation){
console.error('Failure Notification', response.responseText);
Ext.Msg.alert('Loading failed', response.statusText);
}
}
}
});
Adding params to proxy and read ajax store
prj.stores.contactInfoId.getProxy().extraParams.partyID = options.partyID;
prj.stores.contactInfoId.getProxy().extraParams.eventName = options.eventName;
prj.stores.contactInfoId.read();
Hope this helps.
回答2:
For dynamically setting extra parameters:
If you want to set single parameter at a time, you can use following
var proxy= myStore.getProxy();
proxy.setExtraParam('param1', 'value 1' );
proxy.setExtraParam('param2' , 'value 2' );
myStore.load();
If you want to set multiple parameters at a time, you can use following
proxy.setExtraParams({
'param1':'value 1',
'param2':'value 2'
});
回答3:
You could try using extraParams
:
Ext.regStore('newsStore', {
model: 'News',
autoLoad: true,
proxy: {
type: 'ajax',
url: '../news/list.form',
reader: {
type: 'json',
root: ''
},
extraParams: {
format: 'json'
}
},
});
回答4:
I suggest you a more elegant solution, the Sencha way to do that:
//Take your store
var store = Ext.StoreMgr.get('YOUR_STORE_ID');
//Apply the params
Ext.apply(store.getProxy().extraParams, {
partyID: options.partyID,
eventName: options.eventName
});
//Reload your store
store.contactInfoId.read();
Hope this helps.
来源:https://stackoverflow.com/questions/6120713/how-can-i-change-add-params-on-a-store