afterrender在EXTJS网格中使用组合框时不起作用
问题描述:
这是我在网格内组合框的代码。afterrender在EXTJS网格中使用组合框时不起作用
{
header: 'FSCS',
dataIndex: 'acntOvrrideTypeCd',
flex: 1,
renderer: function(val, metaData, record, rowIndex, colIndex) {
var id = Ext.id();
var store = new Ext.data.Store({
fields: ['code', 'description'],
data: [{
"code": "",
"description": ""
}, {
"code": "E",
"description": "E"
}, {
"code": "D",
"description": "D"
}, {
"code": "S",
"description": "S"
}]
});
Ext.Function.defer(
(function() {
var cb = Ext.create('Ext.form.ComboBox', {
id: 'acntOvrrideTypeCd-' + rowIndex,
queryMode: 'local',
renderTo: id,
store: store,
forceSelection: true,
triggerAction: 'all',
lazyRender: true,
size: 5,
valueField: 'code',
displayField: 'description',
value: val
//listeners:{
// scope: this,
// 'select': Ext.getCmp('amlFscsForm').controller.amlShow(rowIndex)
//}
});
cb.on(afterrender, function() {
console.log("------- box---" + rowIndex);
Ext.getCmp('amlFscsForm').controller.amlShow(rowIndex);
});
}), 0.25);
console.log("i----------" + id);
return (Ext.String.format('<div id="{0}"></div>', id));
}
}
“afterrender”事件未被解雇。我需要在渲染后启用或禁用组件。
任何人都可以帮忙。
答
这只是一个错字,afterrender应该在引号中,否则您只会添加未定义事件的函数。
cb.on('afterrender',function(){
console.log("------- box---" + rowIndex);
Ext.getCmp('amlFscsForm').controller.amlShow(rowIndex);
});
答
您的代码有几个问题。
它看起来像你想创建一个网格的渲染功能的组合框(代码顶部没有得到包括在代码块)。你最好使用
Ext.grid.plugin.CellEditing
插件,它会根据需求创建一个字段,而不是在列呈现时。另外,每当网格视图刷新时,您将为网格中的每一行创建另一个存储区和组合框。性能不佳,对用户体验也不利。-
当调用延迟时,持续时间以毫秒为单位,而不是秒。另外,您不需要将函数包装在括号中。只需给它自己的功能。就像这样:
Ext.defer(function(){ // do stuff }, 25);
设置lazyRender为true,只有当你的组件是一些容器,它不会立即呈现其所有组件(如一个tabpanel)的子工程。
创建组合框时,只需在组合框中设置禁用的配置,而不是在创建时,可能会更容易,除非在创建时没有可用的信息。
-
像nscrob所说的,当使用
on
方法时,您需要将事件指定为字符串。如果您使用监听器的配置(您已注释掉),你可以这样做:listeners: { afterrender: function(){ console.log("------- box---" + rowIndex); Ext.getCmp('amlFscsForm').controller.amlShow(rowIndex); }, select: function(){ Ext.getCmp('amlFscsForm').controller.amlShow(rowIndex); } }
需要注意的是这些监听功能的默认组件本身(你的组合框)的范围,以便
scope: this
是不必要的很重要。除非你希望范围是任何对象创建这个组合框,那就是。
第一点是最重要的。看看使用CellEditing(或RowEditing)插件,我保证事情会更顺利。