Extjs keeping current select items in combo and ad

2019-09-18 09:03发布

问题:

I have a Role combo box which already have 3 item (loaded User Model). Now I need to add the 4th item to the selection but it doesn't keep the current items, and when I add the 4th one, it will be the only item selected in combo.

Is there anyway to implement this behavior ? My grid record is selected like this

 doSelectUser: function(grid, record) {
        var me = this;
        var selectedRoleVals = record.get('roles');
        me.getUserForm().loadRecord(record);

And then I click the combo box in User Form:

 manageusers userform combobox[name=roles]': {
                select: this.doSelectRole
            }

combo handler

doSelectRole: function(combo, records) {
        var me = 
        var rec = records[0];

回答1:

I suspect you are doing something like

combo.getStore().loadRecords(arrayOfRecords);

You need to be doing

combo.getStore().loadRecords(arrayOfRecords, {addRecords: true});

loadRecords by default overwrites the contents of the store with the new data.

And to add a simple record to your combo box

Ext.ComponentQuery.query('combo[itemId=theComboItemId]')[0].getStore().add({value: 'aRoleValue', displayText: 'A new role'});