在 Ext.Define 中创建 xtype 并在 TabPanel 项中调用它:[]
我一般来说是 extjs 的新手,特别是 4 版本:
我创建了一个类:
Ext.define('MyPanel', {
extend:'Ext.panel.Panel',
views: ["MyPanel"],
config: {
width: 200,
height: 300,
title: "HELLO"
},
constructor:function(config) {
this.initConfig(config);
return this;
},
alias: 'widget.MyPanel'
});
接下来,我想在 tabPanel 项中以 XTYPE 的形式调用该类:[]:
我确实喜欢这样:
items: [{
title: 'Kontakt',
id: 'kontaktTab',
closable:true,
closeAction: 'hide',
layout: 'fit',
items:[{
xtype: "MyPanel"
}]
还没有运气,我得到的只是: 无法创建无法识别的别名的实例:widget.MyPanel”
你一定会想,真是个菜鸟…… ;-)
请有人帮忙!
I am new to extjs in general, specially to 4 version:
I have created a class:
Ext.define('MyPanel', {
extend:'Ext.panel.Panel',
views: ["MyPanel"],
config: {
width: 200,
height: 300,
title: "HELLO"
},
constructor:function(config) {
this.initConfig(config);
return this;
},
alias: 'widget.MyPanel'
});
Next, I want to call this class in form of XTYPE in a tabPanel items:[]:
I did like this:
items: [{
title: 'Kontakt',
id: 'kontaktTab',
closable:true,
closeAction: 'hide',
layout: 'fit',
items:[{
xtype: "MyPanel"
}]
No luck yet, all I get is :Cannot create an instance of unrecognized alias: widget.MyPanel"
You must think, what a noob....
;-)
Someone please help!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当您定义视图(MyPanel)时,为什么要设置
views
属性?当您使用新视图时,您需要在
requires
中指定它。这是一个例子:When you are defining your view (MyPanel), why have you set
views
property?And when you are making use of the new view, you need to specify it in
requires
. Here is an example:嗯,您是否尝试过小写您的别名。我认为别名总是以小写形式存储和获取,但不确定
Hrm, have you tried lowercasing your alias. I thought aliases were always stored and fetched lowercase, but not sure about it
啊,呵呵,我完全忽略了一些事情:
使用“别名”,您将在 ExtJS 类列表中创建一个新的类引用。因此,通过像上面那样添加别名,您可以通过调用来实例化它。
但是,如果您要添加带有 xtype 说明符的实例,则必须省略小部件部分,只需执行以下操作:
使用上面的代码,Ext 将查找具有以下类型的类:别名“widget.MyPanel”。
除此之外,我认为你的构造函数看起来有点时髦。构造函数不应返回自身(例如,就像在 Perl 构造函数中所做的那样)
这就足够了:
干杯,让我知道它是否有帮助
抢
Ah, hehe, I completely overlooked something:
with an 'alias' you are creating a new class reference in the ExtJS class list. So by adding the alias like you did above, you can instantiate it by calling
However, if you are adding an instance with a xtype specifier you have to omit the widget part and just do:
With the above code, Ext will look for class with the alias 'widget.MyPanel'.
Apart from this, I think your constructor is a bit funky looking. The constructor should not return itself (like you would do in a Perl constructor for instance)
This is enough:
Cheers and let me know if it helps
Rob
你所要做的就是像这样声明它:
然后像这样使用它:
你可能需要需要它:
并将 mypanel.js 放在 app 文件夹中
希望这会有所帮助
all u have to do is declare it like that :
and then use it like this:
and you may need to require it :
and put the mypanel.js an app folder
hope this helps