1

所以基本上我正在尝试做与我在上一个问题中所做的相同的事情 - 链式组合框在更改父 cb 时显示 valuefield 而不是 displayfield 但现在我希望能够在不选择父级的情况下选择子组合。

这是我为进行基本过滤所做的工作,但我坚持让选择子 cb 成为可能。

    Ext.define('AppTest.CategoryViewModel', {
    extend: 'Ext.app.ViewModel',
    alias: 'viewmodel.category',
    stores: {
        categories: {
            fields: ['id', 'name'],
            proxy: {
                type: 'ajax',
                url: 'categories.json',
                reader: {
                    type: 'json'
                }
            }
        },
        users: {
            storeId: 'userStore',
            fields: ['id', 'category_id', 'number'],
            autoLoad: true,
            filters: [{
                property:'category_id',
                disabled: '{!categoryCombo.selection}',
                //disableOnEmpty:true,
                value: '{categoryCombo.selection.id}',
                /*filter: function (item) {
                    var me = this,
                        filterFn = me._filterFn || me.getFilterFn(),
                        convert = me.getConvert(),
                        value = me._value;
                    me._filterValue = value;
                    console.log(value);
                    me.isDateValue = Ext.isDate(value);
                    if (me.isDateValue) {
                        me.dateValue = value.getTime();
                    }
                    if (convert && !me.preventConvert[me.getOperator()]) {
                        me._filterValue = convert.call(me.scope || me, value);
                    }

                    return filterFn.call(me.scope || me, item);
                },*/

                //extjs is seems to be bugged here, disable doesn't work without it.
                updateDisableOnEmpty: function(disableOnEmpty) {
                    var disabled = this.getDisabled();
                    if (disableOnEmpty) {
                        disabled = Ext.isEmpty(this.getValue());
                    }
                    this.setDisabled(disabled);
                }


                //filterFn:function(item){
                    //console.log(new Error().stack);
                //}
            }],
            proxy: {
                type:'ajax',
                url:'users.json',
                reader: {
                    type:'json'
                }
            }
        }
    }
});

https://fiddle.sencha.com/#fiddle/103r

我错过了什么?

4

1 回答 1

1

自己做的。

所以我不得不在父配置中定义发布者:

users: {
        alias:'store.users',
        fields: ['id', 'category_id', 'number'],
        autoLoad: true,
        filters: [{
            property:'category_id',
            value: '{categoryCombo.value}',
            //disabled: '{!categoryCombo.selection}',
            disableOnEmpty:true,
            //filter: function (item) {
            //    var me = this,
            //        filterFn = me._filterFn || me.getFilterFn(),
            //        convert = me.getConvert(),
            //        value = me._value;
            //    me._filterValue = value;
            //    console.log(value);
            //    me.isDateValue = Ext.isDate(value);
            //    if (me.isDateValue) {
            //        me.dateValue = value.getTime();
            //    }
            //    if (convert && !me.preventConvert[me.getOperator()]) {
            //        me._filterValue = convert.call(me.scope || me, value);
            //    }
            //
            //    return filterFn.call(me.scope || me, item);
            //},
            updateDisableOnEmpty: function(disableOnEmpty) {
                var disabled = this.getDisabled();
                if (disableOnEmpty) {
                    disabled = Ext.isEmpty(this.getValue());
                }
                this.setDisabled(disabled);
            }


            //filterFn:function(item){
                //console.log(new Error().stack);
            //}
        }],
        proxy: {
            type:'ajax',
            url:'resources/data/users.json',
            reader: {
                type:'json'
            }
        }
    }

 {
             //   store: 'categories',
                bind: {
                    store: '{categories}'
                },

                xtype: 'combo',
                reference: 'categoryCombo',
                displayField: 'name',
                valueField:'id',
                publishes:'value',
                name: 'category',
                typeAhead: false,
                fieldLabel: 'Category',
                emptyText: 'Select a category...',
                anchor: '95%'
            },
            {
                xtype: 'combo',
                name: 'user',
                reference: 'userCombo',
                fieldLabel: 'User',
                displayField: 'number',
                valueField: 'id',
                hiddenName: 'id',
                emptyText: 'Select a user...',
                anchor: '95%',
                //store: {
                //    type:'users'
                //},
                bind: {
                    fieldLabel: '{categoryCombo.selection.name}',
                    //filters: [{
                    //    property:'category_id',
                    //    value: '{categoryCombo.value}'
                    //    //disabled: '{!categoryCombo.selection}',
                    //    //disableOnEmpty:true
                    //}],
                    store: '{users}'
                },
                listeners: {
                    change: 'onSelectChange'
                }
            }

在幕后这个配置和绑定存储有什么区别?绑定是如何影响性能的?这是有棱角的吗?

于 2015-10-28T11:09:41.943 回答