How to add an empty item to ExtJS combobox?

前端 未结 6 681
慢半拍i
慢半拍i 2020-12-16 12:33

I want to add and empty item (display value is blank, item height is kept as normal) to an Ext.form.ComboBox. I refered 2 links below to configure my combobox, but it still

6条回答
  •  死守一世寂寞
    2020-12-16 12:57

    Since your adding the combobox values later, why not just initialize the store with one blank value:

    store : new Ext.data.JsonStore({
        fields : ['id', 'fullName'],
        data : [{id: 0, fullName: ''}]
    }),
    

    Later when you do store.add(theRestOfThem), that blank one will still be there.

    Had to revisit this today (15 Apr 2017) for ExtJS 4.2:

    The easiest way is to include an empty string in the store as above, it can also be done with a load listener on the store:

    listeners: 
    {
        load: function(store, records) 
        {
            store.insert(0, [{
                fullName: '',
                id: null
            }]);
        }
    }
    

    Then add a tpl config to the combobox with   after the display field:

    tpl: '
    {fullName} 
    ',

    (the display field is fullName in the OPs case)

提交回复
热议问题