首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Ext.panel.Panel中查找字段

在Ext.panel.Panel中查找字段
EN

Stack Overflow用户
提问于 2017-11-01 13:57:09
回答 3查看 2K关注 0票数 1

Ext.form.Panel中,我们可以找到如下所有字段:form.findField('field_name')

是否有一种在Ext.panel.Panel中查找字段的简单方法?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-11-01 15:13:11

是否有一种在Ext.panel.Panel中查找字段的简单方法?

是的,在面板或任何其他组件(只包含某些项的组件)中,您可以使用不同的方式找到组件。

1.使用下降()检索与传递的选择器匹配的容器的第一个后代。

2.使用getComponent()尝试默认的组件查找。如果在普通项中找不到组件,则搜索dockedItems并返回匹配的组件(如果有的话)。

3.使用Ext.ComponentQuery.query提供对文档中的组件(全局)或特定Ext.container.Container的搜索,其语法类似于CSS选择器。返回匹配组件的数组或空数组。

在这里,我创建了一个森查小提琴演示,您可以在这里检查它是如何工作的。

代码语言:javascript
复制
Ext.create('Ext.panel.Panel', {
    bodyPadding: 5, // Don't want content to crunch against the borders
    width: '100%',
    title: 'Find Components',
    layout: {
        type: 'vbox',
        align: 'center',
        pack: 'center'
    },
    items: [{
        xtype: 'textfield',
        name: 'fullname',
        itemId: 'fullname',
        fieldLabel: 'Name'
    }, {
        xtype: 'datefield',
        name: 'dob',
        itemId: 'dob',
        fieldLabel: 'Date Of Birth'
    }, {
        xtype: 'combobox',
        name: 'state',
        itemId: 'state',
        store: Ext.create('Ext.data.Store', {
            fields: ['abbr', 'name'],
            data: [{
                "abbr": "AL",
                "name": "Alabama"
            }, {
                "abbr": "AK",
                "name": "Alaska"
            }, {
                "abbr": "AZ",
                "name": "Arizona"
            }]
        }),
        fieldLabel: 'Choose State',
        queryMode: 'local',
        valueField: 'abbr'
    }, {
        xtype: 'numberfield',
        name: 'mobile',
        itemId: 'mobile',
        fieldLabel: 'Mobile Number'
    }, {
        xtype: 'textareafield',
        name: 'feedback',
        itemId: 'feedback',
        fieldLabel: 'Feedback'
    }, {
        xtype: 'button',
        text: 'Get All Component',
        handler: function () {
            this.up('panel').doGetAllComponent(['dob','fullname','state','feedback','mobile']);
        }
    }],
    renderTo: Ext.getBody(),
    doGetAllComponent: function (data) {
        var panel = this;
        data.map(function (value) {
            console.log('find component using name config');
            console.log(panel.down('[name=' + value + ']'));
            console.log('find component using itemId');
            console.log(panel.down('#' + value));
            console.log('find component using getComponent ');
            console.log(panel.getComponent(value));
            console.log('find component using Ext.ComponentQuery.query()');
            console.log(Ext.ComponentQuery.query('#' + value)[0]);
        });
    }
});
票数 3
EN

Stack Overflow用户

发布于 2017-11-01 14:27:19

Ext.ComponentQuery.query();是你在这里的朋友。基本上,这个函数允许您使用jquery选择器搜索应用程序中的任何ext元素。请参阅:http://docs.sencha.com/extjs/6.0.1/classic/Ext.ComponentQuery.html

另一个选项是使用down()函数搜索对象的子对象,或者使用up()搜索祖先。即:panel.down('field')生成所有字段xtype元素,这些元素(在任何级别上)都是面板变量中的任何元素的后代。注意:并非所有Ext元素都有向上和向下的方法。在这种情况下,仍然可以使用组件查询,并表示选择器部分中的层次结构。

票数 0
EN

Stack Overflow用户

发布于 2017-11-03 03:37:48

Ext.ComponentQuery、up/Down、Ext.get()通常会影响应用程序的性能。您可以使用计时器函数测试组件拉出的行为。我的建议是最好选择命名 reference

视图

代码语言:javascript
复制
{
    xtype: 'numberfield',
    name: 'mobile',
    itemId: 'numMobileId',
    fieldLabel: 'Mobile Number'
},

控制器:

代码语言:javascript
复制
refs:{
  'numMobileId' : 'PersonalInfo [itemId='numMobileId']';
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47056578

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档