Geo*_*rge 0 typescript ionic-framework angular
我有这个数组:
this.menuItems = [
{
category: 'category 4',
items: [
{
type: 'link',
icon: '',
},
{
type: 'link',
icon: '',
},
]
},
{
category: 'category 1',
items: [
{
type: 'text',
icon: 'pencil'
},
{
type: 'checkbox',
icon: 'pencil'
},
]
},
Run Code Online (Sandbox Code Playgroud)
我想从menuItemstype = 中删除对象checkbox。我试过这样:
this.menuItems.forEach(category => {
category.items.forEach((item, index) => {
if (item.type === 'checkbox') {
category.splice(index, 1);
}
});
});
Run Code Online (Sandbox Code Playgroud)
但不工作。你能帮我一些建议吗?提前谢谢
const menuItems = [
{
category: 'category 4',
items: [
{
type: 'link',
icon: '',
},
{
type: 'link',
icon: '',
},
],
},
{
category: 'category 1',
items: [
{
type: 'text',
icon: 'pencil',
},
{
type: 'checkbox',
icon: 'pencil',
},
],
},
];
const result = menuItems.map(item => ({ ...item, items: item.items.filter(i => i.type !== 'checkbox') }));
console.log(result);Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
49 次 |
| 最近记录: |