Extjs keeping current select items in combo and adding new items

╄→尐↘猪︶ㄣ 提交于 2019-12-24 22:17:23

问题


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'});


来源:https://stackoverflow.com/questions/26655312/extjs-keeping-current-select-items-in-combo-and-adding-new-items

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!