javascript 在 ExtJS4 中替换 Ext.reg() (xtype)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5380770/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 17:00:18  来源:igfitidea点击:

Replacing Ext.reg() (xtype) in ExtJS4?

javascriptextjsmulti-select

提问by Philip Guerrant

I want to use the MultiSelect from 3.3 in Ext JS 4, as described in this previous question:

我想在 Ext JS 4 中使用 3.3 中的 MultiSelect,如上一个问题中所述:

Why are the Ext JS multiselect item selector files not included in the Ext JS 3.3 download and where are they?

为什么 Ext JS 多选项目选择器文件不包含在 Ext JS 3.3 下载中?它们在哪里?

It seems like the way to register xtypeshas changed in Ext JS 4. When I try to import this widget,along with ItemSelector.js, I get an error on Ext.reg().

似乎在 Ext JS 4 中注册xtypes的方式发生了变化。当我尝试导入这个小部件以及 ItemSelector.js 时,我在 Ext.reg() 上遇到错误。

Ext.reg('multiselect', Ext.ux.form.MultiSelect);

//backwards compat
Ext.ux.Multiselect = Ext.ux.form.MultiSelect;
Ext.reg('multiselect', Ext.ux.form.MultiSelect);

//backwards compat
Ext.ux.Multiselect = Ext.ux.form.MultiSelect;

How do I change wdigets to get them to work in Ext JS 4?

如何更改 wdigets 以使它们在 Ext JS 4 中工作?

回答by Philip Guerrant

The Ext JS 4 way is to use the new class system to create your widget: http://www.sencha.com/blog/countdown-to-ext-js-4-dynamic-loading-and-new-class-system/

Ext JS 4 的方式是使用新的类系统来创建你的小部件:http: //www.sencha.com/blog/countdown-to-ext-js-4-dynamic-loading-and-new-class-system /

Make sure you assign your widget an alias using the "widget" namespace. For example:

确保使用“小部件”命名空间为小部件指定别名。例如:

Ext.define('Ext.ux.form.MultiSelect', {
    extend: 'ClassNameYouAreExtending',
    alias: 'widget.multiselect'
});

Then you can refer to the widget by the xtype 'multiselect'. When you use an xtype in Ext JS 4 it looks for a class with an alias of 'widget.[xtype]'.

然后你可以通过 xtype 'multiselect' 来引用小部件。当您在 Ext JS 4 中使用 xtype 时,它​​会查找别名为“widget.[xtype]”的类。

回答by Abdel Raoof

You will have to modify the code to get the MultiSelect component running on ExtJS 4. Here are few changes that you will have to do:

您必须修改代码才能让 MultiSelect 组件在 ExtJS 4 上运行。以下是您必须做的一些更改:

  1. Class definition. ExtJS 3.x used Ext.extend to extend. With the new version, you will have to use Ext.define

  2. In the new version, you can represent a class name as string. Due to this, I think you will not require the Ext.reg method anymore. The Component Manager class to not have register function.

  1. 类定义。ExtJS 3.x 使用 Ext.extend 进行扩展。使用新版本,您将不得不使用 Ext.define

  2. 在新版本中,您可以将类名表示为字符串。因此,我认为您将不再需要 Ext.reg 方法。Component Manager 类没有注册功能。

回答by Brian Moeskau

Well, you're diving into pre-beta territory, so to some extent you're going to have to look at code and figure it out. There is some explanation of the new class system in the blog postintroducing it, and there will be a comprehensive migration guide before 4.0 final comes out. I would definitely pursue this in the Sencha 4.0 forums though since that's where all the Ext 4 experts will be hanging out.

好吧,您正在进入测试版前的领域,因此在某种程度上,您将不得不查看代码并弄清楚。在介绍新的类系统的博文中有一些解释,在4.0 final出来之前会有一个全面的迁移指南。我肯定会在 Sencha 4.0 论坛中讨论这个问题,因为所有 Ext 4 专家都会在那里闲逛。