通过选择第一个组合框,应显示剩余的值

时间:2013-06-30 05:02:56

标签: javascript extjs4

通过选择第一个extjs组合框,其余值应显示在表单中。

我正在使用Extjs创建一个地址簿应用程序。

通过选择第一个组合框,剩余的值应以下面的形式显示。

以下是代码:

Ext.define('User', {
    extend: 'Ext.data.Model',
    fields: [{name:'id', type: 'int'}, 
             {name: 'FirstName', type: 'string'},
             {name: 'EmailAddress', type: 'string'}]
});

user : [{"FirstName": "sssss", "EmailAddress": "bbb@gmail.com}, {"FirstName": "bbbb", "EmailAddress": "aaa@gmail.com"}]

通过从组合框中选择FirstName,EmailAddress应显示在下面的文本字段中。

var cntry_panel = new Ext.Panel({
    header: false,
    id: 'org-main',
    layout: 'form',
    labelWidth: 200,
    border: false,
    bodyStyle: 'padding:15px',
    title: 'Select Country And State',
    labelAlign: "right",
    renderTo: Ext.getBody(),
    items: [{
        xtype: 'combo',
        fieldLabel: 'First Name',
        id: 'Name',
        store: user, 
        displayField: 'FirstName',
        mode: 'remote',
        width: 260,
        forceSelection: true,
        triggerAction: 'all',
        emptyText: 'Select FirstName...',
     }, {
         xtype: 'combo',
         fieldLabel: 'Email Address',
         store: user, 
         mode: 'local',
         width: 150,
         forceSelection: true,
         triggerAction: 'all',
         selectOnFocus: true
    }]
});

1 个答案:

答案 0 :(得分:0)

首先,您的电子邮件地址字段可能应为textfield,除非您将该字段用作combo的值列表。

接下来,为您的电子邮件字段添加itemId属性,例如emailField,以便于访问。

然后,在First Name字段的配置中,为select事件添加一个监听器:

{
    xtype: 'combo',
    fieldLabel: 'First Name',
    //...other properties...
    listeners: {
        select: function(combo, records) {
            combo.up('#org-main').down('#emailField').setValue(records[0].get('email'));
        }
    }
}

您应该查看Ext.form.field.ComboBox上事件的文档,这是一个非常常见的操作,如果您将使用大量的ExtJS,这将非常重要。 http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.form.field.ComboBox

相关问题