sol*_*ssf 0 singleton extjs global-variables
我试过像这样制作一个extjs全局变量类:
Ext.define('ccc.global.GlobalVariables', {
singleton: true,
username: 'hi user',
password: '',
clientID: '',
token: ''
});
Run Code Online (Sandbox Code Playgroud)
然后在控制器中我尝试更改变量,如下所示:
ccc.global.GlobalVariables.username = loginData.username;
Run Code Online (Sandbox Code Playgroud)
现在我试图在不同的模型代理中访问这些变量,并且它不断返回原始值'hi user'.
proxy: {
type: 'ajax',
extraParams: {
'username': ccc.global.GlobalVariables.username
},
Run Code Online (Sandbox Code Playgroud)
有谁看到我做错了什么?
当在代理定义中使用变量时,变量内容在定义时设置到代理中,而不是在实例化时,尤其是在使用时.它不会自动更新.
这就是为什么,至少对于组件,存在bind明确告诉组件哪个配置绑定到外部源的属性,以便在更新源时自动更新它.
IIRC代理不支持可绑定的mixin,因此您必须在每次sync/load/...操作之前手动设置extraParam:
store.getProxy().setExtraParam("username",ccc.global.GlobalVariables.username);
store.load()
Run Code Online (Sandbox Code Playgroud)