【问题标题】:ExtJs select component by itemId starting with a stringExtJs 通过 itemId 选择组件,以字符串开头
【发布时间】:2019-05-31 11:23:52
【问题描述】:

使用 Ext Js 4.1。

我在面板中有多个带有 id 和 itemIds 的复选框:“chA104”、“chA204”、“chB111”等。 我想获取所有以 id (或 itemId) = 'chA' 开头的复选框,以使其禁用。

如何做到这一点? 尝试使用这个:

this.query('*[id^=chA]');

但是得到一个包含多个元素的数组:table、td、input 等。 这样做时:

Ext.query('input[id^=chA]')[0]

我得到一个 html 输入元素。但是当尝试这样做时:

Ext.query('input[id^=chA]')[0].disable();
Ext.query('input[id^=chA]')[0].setDisabled(true);

我收到一个错误。

那么如何获取所有以字符串 id(或 itemId)开头的复选框并使其启用/禁用?

【问题讨论】:

  • 请在 Fiddle 上创建一个示例。

标签: extjs extjs4.1


【解决方案1】:

如果你使用 extjs 复选框,你可以这样做:

//enable/disable
Ext.ComponentQuery.query('checkboxfield{id.search("chA")!=-1}')[0].disable(); 
//check/uncheck                           
Ext.ComponentQuery.query('checkboxfield{id.search("chA")!=-1}')[0].setValue(true);

如果是纯html,只需使用:

//enable/disable
Ext.query('input[id^=chA]')[0].disabled = true;
//check/Uncheck
Ext.query('input[id^=chA]')[0].checked = true;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-21
    • 2022-12-24
    • 2014-08-15
    • 2020-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多