简体   繁体   English

具有2个相同显示值的ExtJS组合框不会更改选择的值

[英]ExtJS Combobox with 2 identical display values not changing value on select

I have a combobox that populates with a list of addresses: 我有一个填充有地址列表的组合框:

this.entityAddressField = new Ext.form.ComboBox(
{
    id: 'entityAddressField',
    fieldLabel: 'Address',
    store: entityAddressStore,
    mode: 'local',
    width: 250,
    valueField: 'entity_address_id',
    displayField: 'address_type',
    tpl: new Ext.XTemplate(
        '<tpl for="."><div class="search-item">',
        '<p><b>{address_type}</b></p>',
        '<p>{address_1}</p>',
        '<p>{address_2}</p>',
        '<p>{city}, {state_code} {zipcode}</p>',
        '</div></tpl>'
    ),
    itemSelector: 'div.search-item',
    hidden: true,
    triggerAction: 'all',   
    listeners: {
        select: function(combo, record, index) {
            me.entityAddressDisplay.update(address_template.apply(record.data));
            me.entityAddressDisplay.show();
        }
    }
});

The list shows the full address when expanded, but once selected the combobox will only show the displayField, which is the address type (Home, Work, etc.). 该列表在展开时显示完整的地址,但是一旦选中,组合框将仅显示displayField,这是地址类型(家庭,工作等)。

In the case that two "Home" addresses are listed (same type but different addresses), if I change the combobox from one "Home" address to the other - calling: 如果列出了两个“家庭”地址(类型相同但地址不同),如果我将组合框从一个“家庭”地址更改为另一个-调用:

this.entityAddressField.getValue();

will return the entity_address_id of the originally selected item, instead of the newly selected. 将返回最初选择的项目的Entity_address_id,而不是新选择的。

Are there rules unknown to me that prevent the combobox from having two records with the same displayField set, even though the valueField between the two is unique? 我是否有规则未知,即使两个之间的valueField是唯一的,也无法阻止组合框的两个记录具有相同的displayField设置?

Or am I missing something else? 还是我想念其他东西?

When the combobox is closed, it will display the displayField value. 关闭组合框时,它将显示displayField值。 It is unaffected by your modified tpl configuration on the combobox. 它不受组合框上修改的tpl配置的影响。

One workaround would be to create a dynamic field in your record definition that concats the values together. 一种解决方法是在记录定义中创建一个动态字段,将这些值连接在一起。

Ext.data.Record.create({
    {name: 'address_type', mapping: 'address_type'},
    ..........,
    ..........,
    ..........,
    // simple name concat
    {name: 'simple_name', mapping: 'address_type+" "+obj.address_1+" "+obj.address_2+"  "+obj.city+", "+obj.state_code+" "obj.zipcode'}
});

You can also nest ternary operators and such into this field if you need to do conditionals on optional fields like address 2.... 如果需要对可选字段(例如地址2)执行条件操作,则也可以将三元运算符等嵌套在此字段中。

Ext.data.Record.create({
        {name: 'address_type', mapping: 'address_type'},
        ..........,
        ..........,
        ..........,
        // simple name concat
        {name: 'simple_name', mapping: 'address_type+" "+obj.address_1+" "+(obj.address_2 ? obj.address_2+"  ": "")+obj.city+", "+obj.state_code+" "obj.zipcode'}
    });

It sounds like you're having a similar problem to this one . 这听起来像你有一个类似的问题这一个 Make sure you have the idProperty set in your store or reader. 确保在商店或阅读器中设置了idProperty It's what the store uses to uniquely identify records it contains. 这就是商店用来唯一标识其包含的记录的方法。

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

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