簡體   English   中英

ExtJS:如何讓用戶在組合框中輸入不在存儲區中的值

[英]ExtJS: How to let user enter a value in Combobox that is not in store

我有一個組合框,其中列出了各種地址。 選擇任何地址后,select事件都會在地圖上繪制該地址。 我想以如下方式更改此程序:如果用戶輸入的地址不是Combo商店的一部分,則該地址仍應顯示在地圖上。 我不需要修改組合商店。 如何才能做到這一點? 哪個事件偵聽器可以觸發此類事件? 我需要交換到文本字段嗎?

{
                xtype: 'combobox',
                name: 'address1',
                style: {
                    marginLeft: '15px'
                },
                store: Ext.create('MyStore'),
                valueField: 'address',
                displayField: 'address',
                triggerAction: 'all',
                emptyText: 'Select Address',
                typeAhead: true,
                minChars: 2,
                typeAheadDelay: 100,
                queryMode: 'remote',
                width: 300,
                queryParam: 'searchAddress',
                hideTrigger:true,
                listeners: {                        
                    select: function(combo, records, eOpts){
                        //Plot the address from records[0].data.address
                    }
                }
            }   

用戶可以按Enter鍵指示該地址已被選擇或輸入。當前,specialkey事件不能總是捕獲它,因為在輸入而不是輸入值時,它會選擇存儲中的第一個值

如果顯示下拉列表,則不會真正捕獲specialkey 這是因為該事件是在模擬keydown其下拉列表中有意識地停止可以看出這里

仍然有對用戶輸入做出反應的方法:

方法1

使用這樣的自定義onFieldMutation方法:

Ext.define('MyCombo', {
    extend: 'Ext.form.ComboBox',
    onFieldMutation: function(e) {
        if (e.getKey() === e.ENTER) {
            // Call address plotting method here
        }
        return this.callParent(arguments);
    }
});

方法二

使用keyup

listeners: {
    keyup: {
        fn: function(e) {
            if (e.getKey() === e.ENTER) {
                // Call address plotting method here
            }
        },
        element: 'inputEl'
    }
}

參見兩種方法: https : //fiddle.sencha.com/#fiddle/sdf

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM