我怎样才能改变/在商店
添加PARAMS在一个煎茶触摸,这里是我的店里声明我怎样才能改变/在商店
Ext.regStore('newsStore', {
model: 'News',
autoLoad: true,
proxy: {
type: 'ajax',
url: '../news/list.form?format=json',
reader: {
type: 'json',
root: ''
}
},
});
如何修改PARAMS?我试过
params:{ format: 'json'}
但它不起作用!
商店声明
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);
}
}
}
});
添加PARAMS到代理和阅读阿贾克斯店
prj.stores.contactInfoId.getProxy().extraParams.partyID = options.partyID;
prj.stores.contactInfoId.getProxy().extraParams.eventName = options.eventName;
prj.stores.contactInfoId.read();
希望ŧ他的帮助。
你可以尝试使用extraParams
:
Ext.regStore('newsStore', {
model: 'News',
autoLoad: true,
proxy: {
type: 'ajax',
url: '../news/list.form',
reader: {
type: 'json',
root: ''
},
extraParams: {
format: 'json'
}
},
});
它的工作原理。你有一个想法如何修改参数?我像这样检索商店:Ext.StoreMgr.get('newsStore')。load();它可能改变extraParams? (Ext.StoreMgr.get('newsStore')。proxy.extraParams ....?) – BasicCoder 2011-05-25 09:40:41
好的,由mehul9595回答(在这篇文章上) – BasicCoder 2011-05-25 13:17:33
我建议你一个更优雅的解决方案,煎茶办法做到这一点:
//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();
希望这有助于。
动态设置额外的参数:
如果你想一次设置一个参数,你可以用以下
var proxy= myStore.getProxy();
proxy.setExtraParam('param1', 'value 1');
proxy.setExtraParam('param2' , 'value 2');
myStore.load();
如果你想一次设置多个参数,你可以使用以下
proxy.setExtraParams({
'param1':'value 1',
'param2':'value 2'
});
它的工作原理,非常感谢。它的完美,正是我期待的:)。我需要有init参数并通过选项/按钮进行更改。谢谢。商店对象上的方法read()和load()之间有什么区别? – BasicCoder 2011-05-25 13:16:23
都具有相同的功能,例如打一个ajax调用并填充商店。使用加载你有可选的配置对象,加载前传递到Ext.data.Operation对象。 – mehul9595 2011-05-25 14:06:47
在Sencha Touch 2.0.1.1 proxy.extraParams = {...}无法正常工作。 改为使用proxy.setExtraParams({...})。 – sunsay 2012-07-13 13:35:31