开发者

Extjs3 Component hierarchy - fetch all child components

I'm facing the following situation.

I have a formpanel, within this formpanel I have another tabpanel in which again form elements are placed that are part of the formpanel. Nothing spectacular. Basically a formpanel with some "subforms" each contained in a tab in a tabpanel.

Now I have added code to dis/enable each subform/tab when a user clicks a button in the toolbar. But in order for validation to skip all the formelements in a disabled tab I need to also disable each form field in the tabpanel individually so it skips validation upon submit.

That's when the trouble begins. Suppose in one of the tabs/subforms i have a fieldset with another nested fieldset. How can i fetch all xtype:field elements contained in the tab/subform?


So basically what i'm asking is how can i fetch all components that are child components of the tab, whatever their depth in the component hierarchy is? When i have a method to collect all child components it's easy to just loop over them and disabled the ones that return true from Ext.isXType('field') ... but i have no idea how to gather all subcomponents when i have a refe开发者_如何学运维rence to it's containing component.


This way:

var componentsArray = container.findByType('component');

Or even this

var componentsArray = container.findBy(function(c) {return true});

(should be even faster)

It should be noted however, than this will not return components within tbar, bbar, buttons properties of Ext.Panel descendands.


Edit Use findByType from Mchl's answer. I got mislead by an error in the Ext documentation.


You can use Ext.Container.prototype.cascade

cascade( Function fn, [Object scope], [Array args] ) : Ext.Container

Cascades down the component/container heirarchy from this component (called first), calling the specified function with each component. The scope (this) of function call will be the scope provided or the current component. The arguments to the function will be the args provided or the current component. If the function returns false at any point, the cascade is stopped on that branch.

I used it this way while testing this answer:

var children = [];
this.cascade(function(cmp) {
  if (cmp.isXType('field')) {
    children.push(cmp)
  }
});

children contained 446 instances of field at all different levels.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜