Best approach to creating a custom ExtJS of pure HTML

本秂侑毒 提交于 2019-12-03 16:30:55

This looks like some serious over-engineering. The purpose of making something a component is so that it's reusable in some fashion. Maybe if it had configs for the title, class, etc. I could see the point, but as it is, there's no reason (unless you have drastically over-simplified for the purpose of posting here?). Why not just put this div directly into the page code or Panel config or whatever is containing it?

FYI, visually-rendered components usually subclass BoxComponent since it provides sizing and layout capabilities in addition to the Component API. BoxComponents work much easier with the standard Ext layouts.

EDIT: Note that in Ext 4, BoxComponent no longer exists. You'd now simply use Component as a base for most simple widgets like this.

Mariano Desanze

@bmoeskau answer is obviously correct (he cofounded ExtJS).

But I wanted to clarify about the OP's Edit, which is ok but it may confuse someone looking for a similar minimal rendering still using an Ext components. This is the code I'm talking about:

{ html: '<div class="title-bar"><h1>My App</h1></div>' }

The above code will create an entire Ext.Panel (because "panel" is the defaultType of every Ext.Container), and that is handy because panels have many features, but maybe you look at the code and you expect to get just the intended div, and not a bunch of nested divs which will contain your title-bar div. If that is the case you are probably looking for something similar to this:

{ xtype: 'box', autoEl: { tag: 'div', cls: 'title-bar', html: '<h1>My App</h1>' }}

And this will render just the div expected with your custom class and your html inside, but that div will also have the rest of ExtJS positioning and sizing information which will let you take advantage of Ext's layout system.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!