extjs 4 动态启用操作列项

发布于 2025-01-07 09:57:18 字数 1260 浏览 2 评论 0原文

使用 4.0.6 我有一个带有操作列的网格面板,其中有两个项目,一个删除按钮和一个查看按钮。删除按钮被禁用,但在某些情况下需要启用它(如果用户是管理员)。所以我试图在代码中启用它。

这是视图:

Ext.define('PP.view.person.List', {
extend: 'Ext.grid.Panel',
alias: 'widget.personlist', 
title: 'Current people',
store: 'People',
columnLines: true,

initComponent: function () {
    this.columns = [
        { header: 'Id', dataIndex: 'personId', flex: 1, sortable: true },
        { header: 'Title', dataIndex: 'title', flex: 1 },
        { header: 'Name', dataIndex: 'name', flex: 1},
        { xtype:'actioncolumn',
            items:[
                {icon:'cross.gif',disabled:true,handler:function(){alert('delete pressed');}},
                {icon:'tick.gif',handler:function(){alert('view pressed');}}
            ]
        }
    ];

    this.callParent(arguments);
}

});

和我用来启用的控制器函数:

enableDel: function () {
    var view = Ext.widget('personlist');
    view.down('actioncolumn').enableAction(0);
}

但我在启动 el 的行的 extjs enableAction 函数内收到错误

me.up('tablepanel').el.select

未定义。该列也没有启用。谁能告诉我我做错了什么或发布一个有效的例子?如果我

renderTo: Ext.getBody()

在视图中指定,我不会再收到错误,但该列仍然无法启用。所以我认为这一定与渲染有关,但我对此很陌生,我不知道从哪里开始。

Using 4.0.6 I have a gridpanel with an actioncolumn that has two items, a delete button and and view button. The delete button is disabled but there are some circumstances where it needs to be enabled (if a user is an admin). So I am trying to enable it in code.

Here's the view:

Ext.define('PP.view.person.List', {
extend: 'Ext.grid.Panel',
alias: 'widget.personlist', 
title: 'Current people',
store: 'People',
columnLines: true,

initComponent: function () {
    this.columns = [
        { header: 'Id', dataIndex: 'personId', flex: 1, sortable: true },
        { header: 'Title', dataIndex: 'title', flex: 1 },
        { header: 'Name', dataIndex: 'name', flex: 1},
        { xtype:'actioncolumn',
            items:[
                {icon:'cross.gif',disabled:true,handler:function(){alert('delete pressed');}},
                {icon:'tick.gif',handler:function(){alert('view pressed');}}
            ]
        }
    ];

    this.callParent(arguments);
}

});

and the controller function I'm using to enable:

enableDel: function () {
    var view = Ext.widget('personlist');
    view.down('actioncolumn').enableAction(0);
}

but I am getting an error inside the extjs enableAction function on the line that starts

me.up('tablepanel').el.select

the el is undefined. The column doesn't get enabled either. Can anyone tell me what I'm doing wrong or post an example that works? If I specify

renderTo: Ext.getBody()

in the view I don't get the error any more but the column still doesn't enable. So I think it must be something to do with rendering but I'm so new to this I haven't a clue where to start.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦醒时光 2025-01-14 09:57:18

通常,当 el 未定义时,意味着您试图在渲染组件之前访问它。您的 enableDel 函数何时被调用?您可能想尝试将其放入 afterrender 侦听器中。

Generally when el is undefined it means that you are attempting to access it before the component is rendered. When does your enableDel function get called? You might want to try putting it in an afterrender listener.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文