简体   繁体   English

ExtJS ComboBox中的多个字段

[英]ExtJS Multiple fields in ComboBox

I have a store with the following fields: 我有一个具有以下字段的商店:

  • personName PERSONNAME
  • primaryRole primaryRole
  • secondaryRole secondaryRole

I want to populate a combo-box so that I can choose from either their primary or secondary role. 我想填充一个组合框,以便可以从其主要角色或次要角色中进行选择。

The combobox code I currently have looks like this: 我目前拥有的组合框代码如下所示:

roleName: {
    editor: Ext.create('Ext.form.ComboBox', {
        store: persons,
        queryMode: 'local',
        displayField: 'primaryRole',
        valueField: 'primaryRole'
    }),
    displayName: 'Role'
}

Is it possible to populate a combobox from two store fields, if so, how? 是否可以从两个商店字段填充组合框,如果可以,如何?

You can update the tpl and displayTpl configs for the combobox to display the data however you want. 您可以更新组合框的tpldisplayTpl配置,以根据需要显示数据。 Here's an example from the ExtJS 4 documentation: 这是ExtJS 4文档中的一个示例:

// Template for the dropdown menu.
// Note the use of "x-boundlist-item" class,
// this is required to make the items selectable.
tpl: Ext.create('Ext.XTemplate',
    '<tpl for=".">',
        '<div class="x-boundlist-item">{abbr} - {name}</div>',
    '</tpl>'
),
// template for the content inside text field
displayTpl: Ext.create('Ext.XTemplate',
    '<tpl for=".">',
        '{abbr} - {name}',
    '</tpl>'
)

For the displayed value in the field itself, use the displayTpl config (be careful though if you use multiselection). 对于字段本身中的显示值,请使用displayTpl配置(但是,如果您使用多选,则要小心)。 For the underlying Ext.view.BoundList (ie the list which is displayed when the combo is expanded), overwrite the getInnerTpl function (can be done using the combo's listConfig configuration): 对于基础的Ext.view.BoundList (即,展开组合时显示的列表),覆盖getInnerTpl函数(可以使用组合的listConfig配置完成):

editor: Ext.create('Ext.form.ComboBox', {
    store: persons,
    queryMode: 'local',
    displayField: 'primaryRole',
    valueField: 'primaryRole',
    displayTpl: Ext.create('Ext.XTemplate',
        '<tpl for=".">',
            '<tpl if="primaryRole">{primaryRole}<tpl else>{secondaryRole}</tpl>',
        '</tpl>'
    ),
    listConfig: {
        getInnerTpl: function() {
            return '<tpl if="primaryRole">{primaryRole}<tpl else>{secondaryRole}</tpl>';
        }
    })
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM