ExtJS 5:设置初始化的配置变量获胜'从控制器设置后不要粘住

ExtJS 5: Setting initialized config variables won't stick after setting from controller

本文关键字:设置 控制器 初始化 配置 获胜 变量 ExtJS      更新时间:2023-09-26

在一个控制器上,我有一个函数处理一个向下钻取,该函数在另一个控制器的配置变量上设置该记录的信息。

似乎从第一个控制器开始就设置好了。当它切换到另一个控制器时,它表示这些变量是未定义的。发生了什么事?

控制器处理钻取:

// Set site name for Site Summary
 MyApp.app.getController('otherController').setSiteId(siteId);
 MyApp.app.getController('otherController').setSiteName(siteName);
 console.log(MyApp.app.getController('otherController').getSiteId());
 console.log(MyApp.app.getController('otherController').getSiteName());
 // Prints out the correct values that are supposed to be set

其他值不固定的控制器:

Ext.define('MyApp.controller.otherController', {
    extend: 'Ext.app.Controller',
    config: {
        siteId: -1,
        siteName: ''
    },
    init: function() {
    this.listen( {
        component: {            
            'somePnl': {
                beforerender: this.onBeforeRender
            },
// stuff
    onBeforeRender: function() {
        console.log("this.siteName = " + this.siteName);
        console.log("this.siteId = " + this.siteId);
    },
    // Prints out 'undefined'
}

我似乎不明白为什么这些变量的设置没有坚持

ExtJS建议使用生成的setter和getter进行配置。直接访问没有记录。

文件:http://docs.sencha.com/extjs/4.2.1/#/api/Ext.Class-cfg-config

所以使用

console.log("this.siteName = " + this.getSiteName());
console.log("this.siteId = " + this.getSiteId());

是最好的做法,应该做好这项工作。

显然,使用下划线似乎有效。。。

console.log("this.siteName = " + this._siteName);
console.log("this.siteId = " + this._siteId);