在 Ext.Define 中创建 xtype 并在 TabPanel 项中调用它:[]

发布于 2024-11-07 22:28:45 字数 728 浏览 0 评论 0原文

我一般来说是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

背叛残局 2024-11-14 22:28:45

当您定义视图(MyPanel)时,为什么要设置 views 属性?

Ext.define('MyPanel', {
    extend:'Ext.panel.Panel',
    alias: 'widget.MyPanel'
    views: ["MyPanel"],    <------ Why do you need this???
    config: {
        width: 200,
        height: 300,
        title: "HELLO"
    },
    constructor:function(config) {
        this.initConfig(config);
        return this;
    }
});

当您使用新视图时,您需要在 requires 中指定它。这是一个例子:

Ext.define('MyApp.view.Viewport',{
    extend: 'Ext.container.Viewport', 
    layout: 'border',
    requires: [
        'MyPanel'       <--- This will ensure that this view file needs to be loaded
    ],  
    .
    .
    .
    items: [{
        title: 'Kontakt',
        id: 'kontaktTab',
        closable:true,
        closeAction: 'hide',
        layout: 'fit',
        items:[{
            xtype: "MyPanel"
        }]

When you are defining your view (MyPanel), why have you set views property?

Ext.define('MyPanel', {
    extend:'Ext.panel.Panel',
    alias: 'widget.MyPanel'
    views: ["MyPanel"],    <------ Why do you need this???
    config: {
        width: 200,
        height: 300,
        title: "HELLO"
    },
    constructor:function(config) {
        this.initConfig(config);
        return this;
    }
});

And when you are making use of the new view, you need to specify it in requires. Here is an example:

Ext.define('MyApp.view.Viewport',{
    extend: 'Ext.container.Viewport', 
    layout: 'border',
    requires: [
        'MyPanel'       <--- This will ensure that this view file needs to be loaded
    ],  
    .
    .
    .
    items: [{
        title: 'Kontakt',
        id: 'kontaktTab',
        closable:true,
        closeAction: 'hide',
        layout: 'fit',
        items:[{
            xtype: "MyPanel"
        }]
谎言 2024-11-14 22:28:45

嗯,您是否尝试过小写您的别名。我认为别名总是以小写形式存储和获取,但不确定

Hrm, have you tried lowercasing your alias. I thought aliases were always stored and fetched lowercase, but not sure about it

很糊涂小朋友 2024-11-14 22:28:45

啊,呵呵,我完全忽略了一些事情:

使用“别名”,您将在 ExtJS 类列表中创建一个新的类引用。因此,通过像上面那样添加别名,您可以通过调用来实例化它。

var newMyPanel = Ext.create('widget.MyPanel');

但是,如果您要添加带有 xtype 说明符的实例,则必须省略小部件部分,只需执行以下操作:

var myContainer = Ext.create('Ext.panel.Panel',{
    items: [{
        xtype: 'MyPanel'
    }]
});

使用上面的代码,Ext 将查找具有以下类型的类:别名“widget.MyPanel”。

除此之外,我认为你的构造函数看起来有点时髦。构造函数不应返回自身(例如,就像在 Perl 构造函数中所做的那样)

这就足够了:

constructor: function() {
     this.callParent(arguments);
     // Your own code here
}

干杯,让我知道它是否有帮助

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

var newMyPanel = Ext.create('widget.MyPanel');

However, if you are adding an instance with a xtype specifier you have to omit the widget part and just do:

var myContainer = Ext.create('Ext.panel.Panel',{
    items: [{
        xtype: 'MyPanel'
    }]
});

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:

constructor: function() {
     this.callParent(arguments);
     // Your own code here
}

Cheers and let me know if it helps
Rob

茶底世界 2024-11-14 22:28:45

你所要做的就是像这样声明它:

 var panel1 =  Ext.create('Ext.app.myPanel',{title : 'panel 1',height:350});//title and hight are optionals if u have already defined them

然后像这样使用它:

...
items : [panel1 ]
...

你可能需要需要它:

 Ext.require([
, 'Ext.app.myPanel'
]);

并将 mypanel.js 放在 app 文件夹中

希望这会有所帮助

all u have to do is declare it like that :

 var panel1 =  Ext.create('Ext.app.myPanel',{title : 'panel 1',height:350});//title and hight are optionals if u have already defined them

and then use it like this:

...
items : [panel1 ]
...

and you may need to require it :

 Ext.require([
, 'Ext.app.myPanel'
]);

and put the mypanel.js an app folder

hope this helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文