2017-09-15 54 views
0
export default [ 
{ 
    user:{ 
     id: '1', 
     person: 'Theodore Roosevelt', 
     text: 'Believe you can and you\'re halfway there', 
     icon:'man' 
    } 
}, 
{ 
    user:{ 
     id: '2', 
     person: 'Normale', 
     text: 'Change your thoughts and you change your world.', 
     icon:'woman' 
    } 

}, { 
    user:{ 
     id: '3', 
     person: 'Thlt', 
     text: 'Believe you can and you\'re halfway there', 
     icon:'man' 
    } 
}] 

上面的代码是离子工具中数据文件夹下的ts文件。
我想在id的基础上通过点击每个条目前面的删除按钮从这个数组中删除一个条目。 我是新来的离子。我试图.slice没有工作如何删除角2和离子json中的对象

+0

表明您已经尝试了什么 – Sajeetharan

回答

0

const arr = [{ 
 
    user:{ 
 
     id: '1', 
 
     person: 'Theodore Roosevelt', 
 
     text: 'Believe you can and you\'re halfway there', 
 
     icon:'man' 
 
    } 
 
}, 
 
{ 
 
    user:{ 
 
     id: '2', 
 
     person: 'Normale', 
 
     text: 'Change your thoughts and you change your world.', 
 
     icon:'woman' 
 
    } 
 

 
}, { 
 
    user:{ 
 
     id: '3', 
 
     person: 'Thlt', 
 
     text: 'Believe you can and you\'re halfway there', 
 
     icon:'man' 
 
    } 
 
}] 
 

 
const id = '2'; // 2 will be removed 
 
const result = arr.filter(item => (item.user || {}).id !== id) 
 
console.log(result)