【问题标题】:ExtJS Combobox with 2 identical display values not changing value on select具有 2 个相同显示值的 ExtJS 组合框在选择时不会改变值
【发布时间】:2011-04-19 17:35:39
【问题描述】:

我有一个包含地址列表的组合框:

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();
        }
    }
});

列表展开时会显示完整的地址,但一旦选中,组合框将只显示 displayField,即地址类型(家庭、工作等)。

如果列出了两个“家庭”地址(相同类型但地址不同),如果我将组合框从一个“家庭”地址更改为另一个 - 调用:

this.entityAddressField.getValue();

将返回最初选择项目的 entity_address_id,而不是新选择的项目。

是否有我不知道的规则阻止组合框设置两个具有相同 displayField 的记录,即使两者之间的 valueField 是唯一的?

还是我错过了什么?

【问题讨论】:

    标签: javascript extjs


    【解决方案1】:

    当组合框关闭时,它会显示 displayField 值。它不受您在组合框上修改的 tpl 配置的影响。

    一种解决方法是在记录定义中创建一个动态字段,将值连接在一起。

    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'}
    });
    

    如果您需要对可选字段(如地址 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'}
        });
    

    【讨论】:

    • 如果我理解正确,这个动态字段必须用作组合框的 displayField 才能工作?
    【解决方案2】:

    听起来您遇到了与this one 类似的问题。确保您在商店或阅读器中设置了idProperty。这是商店用来唯一标识它包含的记录的东西。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-08
      • 2020-07-03
      • 2011-08-13
      • 2012-06-15
      • 1970-01-01
      • 2021-10-21
      • 1970-01-01
      相关资源
      最近更新 更多