angular6 - 如何动态更新 ng2-smart-table 的自定义部分?
问题描述
在我的 Angular 6 应用程序中,我使用了 ng2-smart-table。现在我需要根据访问权限显示和隐藏自定义操作功能。
我能够管理add、edir和delete部分。有了这个,我还添加了一些自定义图标来获得额外的功能。
custom: [
{ name: 'up', title: '<img src="/pathOfIcon" class="tableIcon up-arrow-true-icon">' },
{ name: 'up-cancel', title: '<img src="/pathOfIcon" class="tableIcon up-arrow-cancel-icon">' },
{ name: 'down', title: '<img src="/pathOfIcon" class="tableIcon down-arrow-true-icon">' },
{ name: 'down-cancel', title: '<img src="/pathOfIcon" class="tableIcon down-arrow-cancel-icon">' },
]
现在我需要根据访问来管理这个东西。
那么我该如何启用和禁用此图标。
注意:我可以在每一行上应用 css 然后隐藏图标,但我需要在每一行上做一次。
解决方案
您可以在自定义数组中添加图标时添加图标...
试试这个方法
if(access){ // Set you access condition
this.settings.custom.push('{ name: 'up', title: '<img src="/pathOfIcon" class="tableIcon up-arrow-true-icon">' }');
this.settings.custom.push('{ name: 'up-cancel', title: '<img src="/pathOfIcon" class="tableIcon up-arrow-cancel-icon">' },');
}else{
this.settings.custom.push(' { name: 'down', title: '<img src="/pathOfIcon" class="tableIcon down-arrow-true-icon">' }');
this.settings.custom.push('{ name: 'down-cancel', title: '<img src="/pathOfIcon" class="tableIcon down-arrow-cancel-icon">' }');
}
这是添加图标的简单方法...因为custom
是数组,所以您可以在其中推送图标...
希望这可以帮助你...... :)
推荐阅读
- git - git push 不带参数做什么
- ios - Fabric Crashlytics 欢迎窗口不会消失
- ruby-on-rails - 使用 Rails 应用程序安装 ssl 证书的 nginx 配置
- python - 如何在一个函数中设置两个消息处理程序
- python - 在训练时更改模型中 2 层的附加权重
- gitlab - Relation between Gitlab Chat and Mattermost
- reactjs - Unexpected output in react
- common-lisp - conditional returns (nil) as true
- java - @JsonIgnore 字段不使用来自 Postman 的数据
- python - 在 Python 中删除 2D 散点的外壳