Ext JS:xtype有什么用处? [英] Ext JS: what is xtype good for?

查看:109
本文介绍了Ext JS:xtype有什么用处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到Ext JS中有很多示例,其中传递了具有xtype属性的对象文字,而不是实际创建Ext JS对象.

I see there are lot's of examples in Ext JS where instead of actually creating Ext JS objects, an object literal with an xtype property is passed in.

这有什么好处?如果仍然要创建该对象,性能提升(如果是这个原因)在哪里?

What is this good for? Where is the performance gain (if that's the reason) if the object is going to be created anyway?

推荐答案

xtype是识别特定组件的简便方法:panel = Ext.Paneltextfield = Ext.form.TextField等.创建时页面或表单,您可以使用这些xtypes而不是实例化对象.例如,

xtype is a shorthand way to identify particular components: panel = Ext.Panel, textfield = Ext.form.TextField, etc. When you create a page or a form, you may use these xtypes rather than instantiate objects. For example,

items: [{
   xtype: 'textfield',
   autoWidth: true,
   fieldLabel: 'something'
}]

此外,以这种方式创建页面允许Ext JS 懒惰地呈现页面.这是您看到性能提升"的地方.当应用程序加载时,Ext JS不会在用户需要查看它们时呈现组件,而不是创建大量组件.如果只有一页,那没什么大不了,但是如果您使用制表符或手风琴,最初会隐藏许多页面,因此应用程序将更快地加载.

Moreover, creating pages in this manner allows Ext JS to render lazily the page. This is where you see a "performance gain." Instead of creating a large number of components when the app loads, Ext JS renders components when the user needs to see them. Not a big deal if you have one page, but if you exploit tabs or an accordion, many pages are initially hidden and therefore the app will load more quickly.

此外,您可以创建并注册新组件,以创建您选择的xtype. Ext JS同样会懒惰地渲染您的组件.

Furthermore, you may create and register new components creating xtypes of your choosing. Ext JS will similarly render your components lazily.

您还可以按ID检索组件.由于您的组件(以及Ext JS组件)可能提供许多良好的行为,因此有时搜索和检索组件比简单的DOM元素或节点更为方便.

You may also retrieve components by ID. Since your component (as well as the Ext JS components) may provide a bunch of nice behavior, it is sometimes convenient to search for and retrieve a component rather than a simple DOM element or node.

简而言之,xtypes标识组件和组件是Ext JS的关键方面.

In short, xtypes identify components and components are a key aspect of Ext JS.

这篇关于Ext JS:xtype有什么用处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆