0

http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.form.field.ComboBox 有一个 beforeQuery 事件。但是当我尝试这个时,我会抱怨没有查询计划。

这怎么能成立?我在任何地方都找不到有关如何设置查询计划的文档。

                                {
                                    xtype: 'combo',
                                    flex: 2,
                                    fieldLabel: 'other',
                                    displayField: 'city_name',
                                    name: 'city_name',
                                    itemId:'city_name',
                                    emptyText: 'plaats',
                                    store:{
                                        type: 'location.city'
                                    },

                                   beforeQuery: function( queryEvent, eOpts ){
                                        var me = this;

                                        var store = me.getStore();

                                        store.proxy.extraParams={
                                            fieldName: 'city.name',
                                            fieldValue: me.getValue()
                                        };

                                        // return true;
                                    }, ...
4

1 回答 1

0

简而言之:

您正在覆盖 beforeQuery方法而不是侦听 beforeQuery事件beforequery在控制器中侦听事件或向对象添加侦听器,如下所示:

listeners: {
    beforequery: function( queryPlan, eOpts){
        var me = this,
            store = me.getStore();

        store.proxy.extraParams={
            fieldName: 'city.name',
            fieldValue: me.getValue()
        };
        return true; //optional only false would cancel the event see beforQuery method
    }
}

更长的版本:

doQuery方法如下所示:

doQuery: function(queryString, forceAll, rawQuery) {
    var me = this,

    // Decide if, and how we are going to query the store
        queryPlan = me.beforeQuery({
            query: queryString || '',
            rawQuery: rawQuery,
            forceAll: forceAll,
            combo: me,
            cancel: false
        });

    ...some other code where the queryPlan is needed...

        return true;
},

您正在覆盖 beforeQuery 方法并且不返回任何内容(或 true/false),而不是监听事件!

这是 beforeQuery 方法的样子:

beforeQuery: function(queryPlan) {
    var me = this;

    // Allow beforequery event to veto by returning false
    if (me.fireEvent('beforequery', queryPlan) === false) {
        queryPlan.cancel = true;
    }

    // Allow beforequery event to veto by returning setting the cancel flag
    else if (!queryPlan.cancel) {

        // If the minChars threshold has not been met, and we're not forcing an "all" query, cancel the query
        if (queryPlan.query.length < me.minChars && !queryPlan.forceAll) {
            queryPlan.cancel = true;
        }
    }
    return queryPlan;
}

如果您有意覆盖 beforeQuery 方法 => 返回 queryPlan 否则请使用该事件。如您所见,使用该事件,您还可以通过在 beforeQuery 的事件处理程序中返回 false 来取消查询。

于 2013-09-26T13:02:33.387 回答