Extjs保持当前选择项目在组合和添加新项目 [英] Extjs keeping current select items in combo and adding new items

查看:176
本文介绍了Extjs保持当前选择项目在组合和添加新项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个角色组合框,其中已经有3个项目(加载的用户模型)。现在我需要添加第四个项目到选择,但它不保留当前项目,当我添加第四个,它将是组合中选择的唯一项目。



有没有实现这种行为?
我的网格记录选择如下

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

然后点击用户表单中的组合框:

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



组合处理程序

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


解决方案

我怀疑你正在做类似

  combo.getStore()。loadRecords(arrayOfRecords); 

您需要执行

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

loadRecords 默认覆盖

 


$ b

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


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];

解决方案

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

这篇关于Extjs保持当前选择项目在组合和添加新项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆