【发布时间】:2012-01-28 04:05:28
【问题描述】:
如果我在 ExtJS 4 中有一个网格面板,我该如何检查其中的值?
我正在构建一个弹出窗口以向网格面板添加值,并且我想确保用户尝试添加到网格面板的值尚未在网格面板中列出。
我已经搜索了一段时间的文档并在谷歌上搜索并没有找到任何东西。
【问题讨论】:
如果我在 ExtJS 4 中有一个网格面板,我该如何检查其中的值?
我正在构建一个弹出窗口以向网格面板添加值,并且我想确保用户尝试添加到网格面板的值尚未在网格面板中列出。
我已经搜索了一段时间的文档并在谷歌上搜索并没有找到任何东西。
【问题讨论】:
我在http://dev.sencha.com/deploy/ext-4.0.7-gpl/examples/grid/array-grid.html的示例底部添加了以下代码
希望这对您来说是一个开始,尽管您可能需要考虑以下其他事项,以便设计出最强大的解决方案:
代码:
dockedItems: [{
xtype: 'toolbar',
items : [ {
xtype: 'button',
text: 'Seek Value',
handler: function() {
Ext.Msg.prompt('Value in Grid?', 'Search:', function(btn, text){
if (btn == 'ok' && text){
var columnNames = Ext.Array.pluck(grid.columns, 'dataIndex');
grid.store.data.each(function(record, index) {
for (var i=0,n=columnNames.length; i<n; i++) {
var columnName = columnNames[i];
if (columnName) { //protects against null dataIndex using pluck above
if (record.get(columnName) == text) {
console.log(index); //row
console.log(columnName);
return;
}
}
}
});
}
});
}
}],
dock: 'bottom'
}]
【讨论】: