如何在Extjs 6中给视图项配置属性
How to give config property to a view Item in Extjs 6?
在Extjs 6中如何通过绑定或直接分配直接分配配置属性给视图?
Ext.define('App.view.main.Main', {
extend: 'Ext.Container',
config: {
btnLabel: 'MyButton'
},
someOtherProperty:'xyz',
items: [{
xtype:'button',
//text:this.someOtherProperty,
//text:this.btnLabel,
//text:this.getBtnLabel(),
//here accessing this throws error, while loading this refers to windows object and not the class...
width:'150px'
}],
});
我可以将属性移动到ViewModel并访问它,但我的问题是,我们不能将类级属性分配给它的子组件吗?
好吧,并不是说你不能。问题是你在类原型中定义项目——这意味着你不能对那里的实例做任何特定的事情。
这就是initComponent
的作用。我通常在这里定义items
属性,明确用于此目的:
Ext.define('App.view.main.Main', {
extend: 'Ext.Container',
config: {
btnLabel: 'MyButton'
},
someOtherProperty:'xyz',
initComponent: function() {
// The config properties have already been transferred to the instance
// during the class construction, prior to initComponent being called.
// That means we can now call this.getBtnLabel()
this.items = [
{ xtype: 'button',
text: this.getBtnLabel(),
width:'150px'
}]
// Call the parent function as well. NB: After this, items won't be
// a simple array anymore - it gets changed into a collection of
// components.
this.callParent(arguments);
}
});
一般来说,在类级属性中添加对象时要小心,因为它们将成为原型的属性,并在该类的所有实例中共享。
相关文章:
- 如何使用javascript从主svg对象动态创建svg视图框
- 正在使用$location.path(.)路由ng视图
- angular.js没有'无法在PhoneGap中处理视图标记
- 如何包含特定于每个视图angularjs的javascript文件
- 通过在Dojo mobile ViewController.openExternalView中动态更改打开同一外部视图的
- Kendo:我该如何在树视图中创建一个递归的hieiarchy
- Ajax Live搜索发布到Laravel视图
- backbone.js无法渲染视图
- 根据某些条件在视图之间切换
- ng视图外的链接重定向到ng视图内的页面
- RequireJS向模块传递配置总是返回undefined
- 如何在Jquery中发布后将值从视图返回到控制器
- 将日期时间作为 JSON 发送将无法在我的视图中正确显示
- 正在加载视图配置
- AngularJS如何配置一个没有控制器的视图
- 我如何在Ember JS中重新配置视图以不使用defaultContainer ?
- 如何在angular JS中配置视图和控制器模块
- 如何在Extjs 6中给视图项配置属性
- AngularJS UI router:如何配置嵌套的命名视图
- 我应该如何配置我的视图以在 MVC 中获取窗口.父值