有人可以帮我提供一些离子代码吗?
我有一个使用ngFor
显示的项目数组。当用户单击某个项目时,该项目将被推到具有该项目的完整说明并具有完整按钮的另一页。
当用户单击完成按钮时,该项目应从原始阵列中删除。我只是不知道如何从其他组件中切出一个数组。请帮助
答案 0 :(得分:0)
据我了解,您想从数组中删除某个项目。那是对的吗?
在这种情况下,您可以像以下示例一样使用splice
:
let myArray = [{ a: 'firts', b: 'foo' },
{ a: 'second', b: 'bar' },
{ a: 'third', b: 'baz' }];
// to remove the third item from the array do this:
// first argument is the index of the item to remove
// second argument is the number of items to remove
myArray.splice(2, 1);
console.log(myArray) // [{ a: 'firts', b: 'foo' }, { a: 'second', b: 'bar' }]