ExtJS 5:从控制器设置后,设置初始化配置变量不会粘连

时间:2014-09-03 20:50:35

标签: javascript extjs extjs5

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

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

控制器处理深入研究:

// 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'
}

我似乎无法弄清楚为什么这些变量的设置没有坚持

2 个答案:

答案 0 :(得分:1)

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

Doc: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());

是最佳做法,应该完成这项工作。

答案 1 :(得分:0)

显然有下划线似乎正在工作......

console.log("this.siteName = " + this._siteName);
console.log("this.siteId = " + this._siteId);
相关问题