1

我对 EXTJS 很陌生,所以我还不完全了解它是如何工作的,但我设法构建了一个作为选择结果的网格(因此它没有直接映射到表)。此网格的一列是 ID。我还在网格中添加了一个复选框

    this.columns =
    [
        {
            header: 'Selected',
            dataIndex: 'Selected',
            xtype: 'checkcolumn'
        },
        ....rest of the columns

在我的模型上,我有:

fields:
[   
    { name: 'Selected', type: 'bool' },
    { name: 'ID', type: 'int' },
     ...rest of the fields

我需要的是,单击一个按钮(已添加),以获取将 Selected 属性设置为 true 的 ID 列表。

知道我该怎么做吗?

4

1 回答 1

3

这很简单(如果我理解正确的话),网格有一个选择模型来处理这些选择。您只需要获取选择模型并获取所有选定的记录。

还有为每个选择触发的itemclickselectionchange事件。第二个给出了一组选定的记录。

我猜Ext.selection.CheckboxModel你也可能感兴趣。

编辑:

好的,我想以上所有内容都不是您想要的,但可能很有趣。您需要的是遍历可以使用store.each()完成的商店的所有记录。在您的按钮范围内执行此操作,并将一个数组。例子

var myGrid = Ext.getCmp('MyGrid');
var list = [];
myGrid.store.each(function(rec) { 
    if(rec.data.Selected)
        list.push(rec);
    return true;
});

要获取当前选定的记录(模型),请执行以下操作:

var myGrid = Ext.getCmp('MyGrid'),
    sm = myGrid.getSelectionModel(),
    selection = sm.getSelection(), // gives you a array of records(models)
    len = selection.length, 
    i = 0, 
    idList = []; 

for (; i<len; i++) { 
   idList.push(selection[i].data.ID); 
}
于 2012-09-26T15:22:53.573 回答