我有两个有相同记录的网格,但是不同的商店。
基本上,如果在网格A中选择了记录A,我希望禁用网格B中记录A的复选框。
我知道我可以在任何一个网格上侦听“”事件,例如网格A,但是我如何从网格B“获取”记录呢?一旦我有了recs,我可以检查它是否被选中,然后我只需返回true/false就可以启用/禁用其他网格的复选框。
谢谢
发布于 2014-06-25 14:26:19
好的,我最后做了一个校验列,因为行代码更容易完成。您可以在fiddle.sencha.com中抛出这段代码,它会工作的。
示例中的面板1是您可以检查的,它将返回Panel1的值,并将它们与Panel2进行比较,并在两者上都声明检查值。然后你可以做任何你想做的事。
如果您执行了选择模型路由,您将在控制器中放置一个更改函数,而在该函数中只需执行如下操作:
var gridSelected = Ext.ComponentQuery.query('panel1')[0].getSelectionModel().getSelection();
Ext.each(gridSelected, function (value) {
//something
}下面是内联代码:
Ext.onReady(function() {
var locationStore = Ext.create('Ext.data.Store', {
fields: ['id', 'location', 'check'],
proxy: {
type: 'memory'
},
data: [{
id: 1,
location: 'location 1',
check: false
}, {
id: 2,
location: 'location 2',
check: false
}, {
id: 3,
location: 'location 3',
check: false
}, {
id: 4,
location: 'location 4',
check: false
}, {
id: 5,
location: 'location 5',
check: false
}]
});
var locationStore2 = Ext.create('Ext.data.Store', {
fields: ['id', 'location', 'check'],
proxy: {
type: 'memory'
},
data: [{
id: 1,
location: 'location 1',
check: false
}, {
id: 2,
location: 'location 2',
check: false
}, {
id: 3,
location: 'location 3',
check: false
}, {
id: 4,
location: 'location 4',
check: false
}, {
id: 5,
location: 'location 5',
check: false
}]
});
Ext.create('Ext.grid.Panel', {
renderTo: Ext.getBody(),
xtype: 'panel1',
height: 200,
width: 350,
store: locationStore,
columns: [{
text: 'ID',
dataIndex: 'id'
}, {
text: 'Location',
dataIndex: 'location',
flex: 1,
},{
xtype: 'checkcolumn',
header: 'Check',
dataIndex: 'check',
width: 90,
listeners: {
checkchange: function (column, recordIndex, checked) {
var view = panel2.getView(),
record = view.getRecord(view.getNode(recordIndex));
var p1ID = record.get('id');
var p1Check = checked;
Ext.each(locationStore2.data.items, function (value)
{
var p2ID = value.data.id;
var p2Check = value.data.check;
if (p1ID == p2ID){
//here we output the results and you could also do something here.
console.log(p1ID, p1Check, p2ID, p2Check);
}
})
}
}
}]
});
var panel2 = Ext.create('Ext.grid.Panel', {
renderTo: Ext.getBody(),
xtype: 'panel2',
height: 200,
width: 350,
store: locationStore2,
columns: [{
text: 'ID',
dataIndex: 'id'
}, {
text: 'Location',
dataIndex: 'location',
flex: 1,
},{
xtype: 'checkcolumn',
header: 'Check',
dataIndex: 'check',
width: 90,
listeners: {
checkchange: function (column, recordIndex, checked) {
var view = panel2.getView(),
record = view.getRecord(view.getNode(recordIndex));
console.log(record.get('id'));
}
}
}]
});
});发布于 2014-06-25 15:28:51
谢谢你的回答杰西。我想出了这个,其实很简单。在控制器中,我在两个网格上收听了"beforeselect“事件:
//beforeselect handler
gridAHandler: function (grid, rec) {
var gridBSelections = this.getGridB().getSelectionModel().getSelection();
for(var i = 0; i<gridBSelections.length; i++) {
if(rec.get("NAME") == gridBSelections[0].data.NAME) {
return false;
}
}
}因此,如果我要在gridA上进行选择,for循环将检查它在gridB中的对应列是否已被选中。如果它被选中,它将位于gridBSelections数组中,因此gridA名称将等于gridB名称(两个网格上的名称列共享相同的值),因此我返回false;
当然,gridB的处理程序将完全相同,但是值相反。
张贴这是另一个解决方案,任何人有相同的问题。
thx
https://stackoverflow.com/questions/24392575
复制相似问题