typescript - 删除数组打字稿中的列表
问题描述
如何删除 this.cols 中的整行
this.cols 数组的格式
this.cols = [
{ field: 'Id', header: 'ID', width: '70px' },
{ field: 'fullName', header: 'Full Name', width: '200px' }
.....
];
//If does not exist in the access rights list, remove cols
for(var i=0; i<17; i++) {
if (this.getAccessRights.indexOf('Id') !== -1) {
//How do i remove the entire row in this.cols if it matches?
}
}
this.cols 数组的预期输出
this.cols = [
{ field: 'fullName', header: 'Full Name', width: '200px' }
.....
];
尝试使用 remove() 但遇到错误。这里的许多帖子都是关于 python 的,这对我没有用。
解决方案
const index = this.cols.indexOf(key);
this.cols.splice(index, 1);
上面的代码给出了 indexOf() 方法中给定键的索引。然后 splice() 用于从给定索引中删除一个元素。
推荐阅读
- javascript - 在数据表中的导出 excel 上保留小数分隔符
- python - 会话属性 [AWS Lambda / Amazon Alexa Skill]
- c# - 我们可以将数据添加到具有相同分区键和相同行键的表存储中吗
- node.js - ResourceNotFoundException:给定的活动不存在 AWS Personalize
- emacs - 组织模式扩展来为预定的条目/子树着色?
- typo3 - TYPO3 cms-indexed-search 核心扩展缺少 RouteEnhancer?
- spring - java.lang.IllegalStateException:无法在 Spring JPA 单元测试中加载 ApplicationContext
- sql - 为两个不同的输出查询同一列
- javascript - 审计 Node (Javascript) 应用程序实现的工具
- perl - 使用 Perl 获取 UTC/GMT 时间的前一小时