gpt4 book ai didi

android - 访问在 initComponent sencha 中声明的变量

转载 作者:太空狗 更新时间:2023-10-29 14:27:25 25 4
gpt4 key购买 nike

我需要在 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)
});

错误

this.tpl is undefined
[Break On This Error]

html:this.tpl.apply(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)
});

//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);

},

});

关于android - 访问在 initComponent sencha 中声明的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10749251/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com