一个包含comboBox的grid,将comboBox中的value显示在输入框中

来源:互联网 发布:豆瓣 推荐算法 编辑:程序博客网 时间:2024/06/05 11:20

在做包含combobox的eidtorgridPanel的时候,我遇到了当选择了一个下拉列表中的value时,在输入框中却显示的是key值,后来经过网上搜索,发现其实是少了一个render属性,代码如下:

header : '表单名称',
         width : 150,
         dataIndex : 'defineId',
         id : "defineId",
         editor : new Ext.form.ComboBox({
           triggerAction : 'all',//展示所有
           editable : false,//不可手动填写
           scope : this,
           forceSelection : true,
           id : "defineId_combo",
           hiddenName : 'defineId',// 提交到后台的input的name
           store : defineIdStore,//加载过来的数据
           valueField : 'defineId',//输入框中值
           allowBlank : false //不允许为空
          }),

此时运行会出现我所描述的问题,后来我加了如下代码:

renderer : function(value, cellmeta, record) {
          var index = defineIdStore
            .find(Ext.getCmp('defineId_combo').valueField,value);
          var record = defineIdStore.getAt(index);
          var displayText = "";
          if (record == null) {
           displayText = value;
          } else {
           displayText = record.data.defineName;//
          }
          return displayText;
         }

之后就可以显示正常了,并且传值也是对的。
0 0