简体   繁体   English

ExtJS绑定筛选器,并在子组合框中选择默认值

[英]ExtJS Bind Filter and select default value on child combo box

I am trying to create two combo boxes. 我正在尝试创建两个组合框。 The first one shows the country names and the second one shows provinces/states. 第一个显示国家名称,第二个显示省/州。 The idea is to filter the second combo based the selection on first one and put the value of 'VisitingCountryProvince' as the default selection. 这个想法是基于第一个选择过滤第二个组合,并将“ VisitingCountryProvince”的值作为默认选择。 The problem with the below code is, it is not selecting the default value based on the first combo box. 以下代码的问题是,它没有基于第一个组合框选择默认值。 If I remove the bind filter, the second combo box shows the correct value of 'VisitingCountryProvince'. 如果删除绑定过滤器,第二个组合框将显示正确的值“ VisitingCountryProvince”。

Any idea? 任何想法?

{
    xtype: 'fieldset',
    title: 'Visiting Country',
    layout: 'anchor',
    anchor: '-10',
    collapsible: false,
    defaults: {
        xtype: 'combo',
        labelStyle: 'font-weight: bold;',
        flex: 1,
        anchor: '0',
        editable: false,
        forceSelection: true,
        allowBlank: false,
        emptyText: 'Select...',
        queryMode: 'local',
    },
    items: [{
        name: 'VisitingCountry',
        fieldLabel: 'Main',
        reference: 'visitingCountryFieldRef',
        publishes: 'value',
        store: {
            type: 'arraydropdownstore'
        },
        valueField: 'value',
        displayField: 'value'
    }, {
        name: 'VisitingCountryProvince',
        fieldLabel: 'Sub',
        store: {
            type: 'array',
            fields: ['value', 'countryName']
        },
        bind: {
            filters: {
                property: 'countryName',
                value: '{visitingCountryFieldRef.value}'
            }
        },
        valueField: 'value',
        displayField: 'value'
    }]
},

The closest answer to the issue I could find is in here, How to use combo "publishes" value & bindings to filter store on another combo 我可以在这里找到最接近该问题的答案, 如何使用组合“发布”值和绑定来过滤另一个组合上的存储

I just figured out that, I can do either filter or select a default value, not both. 我刚刚发现,我可以过滤或选择默认值,而不是两者都选。 How do I filter and bind a default value from the filtered list? 如何过滤和绑定来自过滤列表的默认值?

You need to write your logic of filtering the values of second combo store in the "select" event handler of the first combo box. 您需要在第一个组合框的“ select”事件处理程序中编写过滤第二个组合存储的值的逻辑。

{
        name: 'VisitingCountry',
        fieldLabel: 'Main',
        reference: 'visitingCountryFieldRef',
        publishes: 'value',
        store: {
            type: 'arraydropdownstore'
        },
        valueField: 'value',
        displayField: 'value',
        listeners:{
             select:function(){
                //Access the second[bound to second combobox]store and apply the 
                //filter, Also there are arguments for select event handler, for this 
                //Please refer docs.sencha.com for extjs version you are using.
             }
        }
}

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

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