Android 访问initComponent sencha中声明的变量

Android 访问initComponent sencha中声明的变量,android,iphone,model-view-controller,extjs,Android,Iphone,Model View Controller,Extjs,我需要以mvc模式在sencha中呈现一个模板,所以在InitComponent中我声明了一些变量,但我无法访问init函数之外的那些变量。我试过了 Ext.define('casta.view.Intro', { extend: 'Ext.tab.Panel', //alias: 'widget.currentDate', //this makes it xtype 'currentDate' //store: 'CurrentDateStore', ini

我需要以mvc模式在sencha中呈现一个模板,所以在InitComponent中我声明了一些变量,但我无法访问init函数之外的那些变量。我试过了

Ext.define('casta.view.Intro', {
    extend: 'Ext.tab.Panel',
    //alias: 'widget.currentDate', //this makes it xtype 'currentDate'
    //store: 'CurrentDateStore',


    initComponent: function(){
        this.planetEarth = { name: "Earth", mass: 1.00 };

        this.tpl = new Ext.Template(['<tpl for".">', '<p> {name} </p>', '</tpl>'].join(''));
        this.tpl.compile();
        this.callParent(arguments);

    },
    html:this.tpl.apply(this.planetEarth)
});

我很确定JavaScript的作用域不是这样的

在您的示例中,有两种方法可以完成您想做的事情:

//this is the bad way imo, since its not really properly scoped.
// you are declaring the planeEarth and tpl globally
// ( or wherever the scope of your define is. )
var plantetEarth = { name: "Earth", mass: 1.00 }
var tpl = new Ext.Template(['<tpl for".">', '<p> {name} </p>', '</tpl>'].join(''));
tpl.compile();
Ext.define('casta.view.Intro', {
    extend: 'Ext.tab.Panel',
    //alias: 'widget.currentDate', //this makes it xtype 'currentDate'
    //store: 'CurrentDateStore',


    initComponent: function(){

        this.callParent(arguments);

    },
    html:tpl.apply(planetEarth)
});
//在imo中,这是一种不好的方式,因为它没有真正正确地确定范围。
//您正在全球宣布planeEarth和tpl
//(或定义的范围在哪里。)
var PlanteEarth={名称:“地球”,质量:1.00}
var tpl=new Ext.Template(['',{name}

','').join(''); tpl.compile(); Ext.define('casta.view.Intro'{ 扩展:“Ext.tab.Panel”, //别名:“widget.currentDate”,//这使其成为xtype“currentDate” //存储区:'CurrentDateStore', initComponent:function(){ this.callParent(参数); }, html:tpl.apply(planetEarth) });

//I would do some variation of this personally.
//It's nice and neat, everything is scoped properly, etc etc
Ext.define('casta.view.Intro', {
    extend: 'Ext.tab.Panel',
    //alias: 'widget.currentDate', //this makes it xtype 'currentDate'
    //store: 'CurrentDateStore',


    initComponent: function(){

        this.tpl = new Ext.Template(['<tpl for".">', '<p> {name} </p>', '</tpl>'].join(''));
        this.tpl.compile();
        this.tpl.apply(this.planetEarth);
        this.html = this.tpl.apply(this.planetEarth)
        this.callParent(arguments);

    },

});
//我个人会做一些变化。
//它漂亮整洁,所有的东西都有适当的范围,等等
Ext.define('casta.view.Intro'{
扩展:“Ext.tab.Panel”,
//别名:“widget.currentDate”,//这使其成为xtype“currentDate”
//存储区:'CurrentDateStore',
initComponent:function(){
this.tpl=new Ext.Template(['',{name}

','').join(''); this.tpl.compile(); 本.tpl.apply(本.planetEarth); this.html=this.tpl.apply(this.planetEarth) this.callParent(参数); }, });
//I would do some variation of this personally.
//It's nice and neat, everything is scoped properly, etc etc
Ext.define('casta.view.Intro', {
    extend: 'Ext.tab.Panel',
    //alias: 'widget.currentDate', //this makes it xtype 'currentDate'
    //store: 'CurrentDateStore',


    initComponent: function(){

        this.tpl = new Ext.Template(['<tpl for".">', '<p> {name} </p>', '</tpl>'].join(''));
        this.tpl.compile();
        this.tpl.apply(this.planetEarth);
        this.html = this.tpl.apply(this.planetEarth)
        this.callParent(arguments);

    },

});