Extjs 4:立即禁用 Extjs 表单中的所有输入元素
我创建了一个 extjs 表单,它使用列布局分为 2 部分,其中有近 10-15 个输入元素。我如何根据条件一次禁用所有这些输入元素。目前我已经创建了一个函数,它获取表单中的所有组件,并使用 ext.each 循环遍历每个元素来禁用它们
这是我使用的函数
function prepare_form_view(form){
var f=Ext.getCmp(form);
var els=f.query('component');
Ext.each(els,function(o){
var xtype=o.getXType();
if(xtype=='textfield'||xtype=='combobox'||xtype=='datefield'||xtype=='textareafield'||xtype=='button'){
o.disabledCls='myDisabledClass';
o.disable();
}
});
}
是否有任何替代方法,以便我可以禁用所有元素而不循环遍历每个元素每个元素。 我也想在其他表单中使用此功能。我正在寻找类似“setFieldDefult”功能的东西。
I have created a extjs form which is divided into 2 parts using column layout and have almost 10-15 input elements in it. How can i disable all these input elements at a time depending on a condition. Currently i have created a function which fetchs all the components in a form and using ext.each loop through each element to disable them
Here is the function that i use
function prepare_form_view(form){
var f=Ext.getCmp(form);
var els=f.query('component');
Ext.each(els,function(o){
var xtype=o.getXType();
if(xtype=='textfield'||xtype=='combobox'||xtype=='datefield'||xtype=='textareafield'||xtype=='button'){
o.disabledCls='myDisabledClass';
o.disable();
}
});
}
Is there any alternative way so that I can disable all elements without looping through each and every elements. I want to use this function with other forms too. I looking for something like 'setFieldDefult' function.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您在 ExtJs 4.x 中使用 FormPanel,这就是您正在寻找的 -
getForm()
方法返回 Ext.form.Basic 对象,通过此类,您还可以访问所有使用getFields()
在此表单上的字段,然后您可以迭代所有字段来执行任何操作。希望这有帮助,祝你好运:-)
If you are using FormPanel in ExtJs 4.x this is what you are looking for -
The
getForm()
method returns the Ext.form.Basic object, with this class, you also could access to all the fields on this form withgetFields()
, then you could iterator all the fields to do anything.Hope this helps and good luck:-)
面板的禁用/启用方法怎么样?这看起来容易多了。
What about panel's disable/enable method? This seems much easier.
这是一个建议.. 既然您说您的表单分为两部分,为什么不将它们放在 FieldSet ?您可以使用一种方法禁用整个字段集,即
这将避免组件循环以及逐个禁用/启用它们。
Here is a suggestion.. Since, you say your form is divided into two parts why don't you put them in a FieldSet ? You can disable the fieldset as a whole with one method ie, setDisabled.
This will avoid the looping of components and disabling / enabling them one after the another.
您可以使用 级联< /a> 表单面板的函数,这是 ExtJs 的方法,但如果你检查级联函数的源代码,你会发现它也使用了 for 循环。使用级联功能的唯一好处是它也适用于具有嵌套面板的表单。我认为在这种情况下你的实施将无法正常工作。
You could use the cascade function of the form panel which is the ExtJs way to to do it but if you check the source code of the cascade function you will see that it uses a for loop also. The only benifit of using the cascade function is that it will work also for forms with nested panels. I think that your implementation will not work properly a case like that.