【问题标题】:Setting combobox value with extjs使用 extjs 设置组合框值
【发布时间】:2015-12-29 15:59:10
【问题描述】:

我有一个带有预填充值的组合框。 单击批准所有按钮时,我想将其值设置为某个值。

这是我的代码

var myStore = new Ext.data.ArrayStore({
                sortInfo: {field: 'Name', direction: "ASC"},
                data: arrHoursData,
                fields: [{name: 'Id', type: 'string'},
                         {name: 'Name', type: 'string'},
                          {name: 'Hours', type: 'string'},
                         {name: 'AssignmentId', type: 'string'},
                         {name: 'Status', type: 'string'}
                    ]
                });
var statusStore = new Ext.data.Store({
    data: arrStatus,
    fields: ['Id', 'Name']
});

var hoursGrid = Ext.create('Ext.grid.Panel', {
                store: myStore,
                width: 340,
                height: 270,
                collapsible: false,
                selType: 'cellmodel',
                plugins: [
                    Ext.create('Ext.grid.plugin.CellEditing', {
                        clicksToEdit:1
                    })
                ],
                columns: [ 
                     {header: 'Id', dataIndex: 'Id',hidden: true},
                     {header: 'Date',dataIndex: 'Name', width:140},
                     {header: 'Hours',dataIndex: 'Hours', width:100,  editor: {xtype: 'numberfield', minValue: 0, allowBlank: false}},
                     {header: 'Status',dataIndex: 'Status', width:100, editor: { xtype: 'combobox',store: statusStore, queryMode: 'local', displayField: 'Name', valueField: 'Id',id:'status'}, renderer: function (value) {
                            var label = '';
                            jQuery.each(arrStatus, function(k,v)
                            {
                                if(v['Id'] == value)
                                    label = v['Name'];
                            });

                            return label;
                        }
                  }
                ]
            });

var win = new Ext.Window({
    closable: true,
    title: "Edit Hours",
    layout: 'form',
    modal: true,
    width: 360,
    height: 300,
    plain: true,
    border: false,
    items: [
         {
            flex: 1,
            xtype: 'container',
            style:'margin-top:15px',
            layout: {
                type: 'hbox',
                align: 'stretch'
            },
            items:[hoursGrid]
        }
    ],
    buttons: [
                    {
            text: 'Approve All',
            handler: function () 
            {
                               Ext.getCmp('status').setValue(approvedStatusId);
            }
         }
    ],

});

win.show(g);

我也尝试使用 getCmp 设置它的值,但它给了我错误 Ext.getCmp('status') 未定义。

【问题讨论】:

  • 当您单击按钮时,您的“状态”字段尚未实例化,因为它是一个列编辑器。
  • @EliasMedeiros 是对的。你真的想在这里做什么?
  • 我在单击时在网格上有一个名为“全部批准”的按钮,我只想将状态组合设置为某个值。

标签: extjs combobox


【解决方案1】:

您必须在记录上设置值,而不是组合框。组合框始终使用记录中设置的值。

grid.getStore().each(function(record) {
    record.set("Status",approvedStatusId);
};

【讨论】:

  • 谢谢 Alexander,我想在点击 Approve all 按钮时执行此操作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多