I am trying to remove the data from a FlatList that it renders the sales from a JSON file data.json
The problem is that when I remove the sale with a certain id and I go back to home page, it shows all the items again.(我正在尝试从FlatList删除数据,该数据从JSON文件data.json
呈现销售信息。问题是,当我删除具有特定ID的销售信息并返回首页时,它将再次显示所有项目。)
So how can I remove the items from the source and the items will be removed for the whole life of the application until the user closes and reopens again?(因此,如何从源中删除项目,并且在用户关闭并再次重新打开之前,这些项目将在应用程序的整个生命周期中被删除?) Any help would be very much appreciated.(任何帮助将不胜感激。)
import data from './data.json';
{
"sales": [
{
"id": 1,
"amount": 100
},
{
"id": 2,
"amount": 200
},
]
}
state = {
data: data.sales
}
onPressRemove(id) {
this.setState(
prevState => {
let data = prevState.data.slice();
let newId = 0;
for (var i=0; i < data.length; i++){
if (data[i].id === id){
newId = i;
}
}
data.splice(newId, 1)
return { data };
});
}
ask by Sachihiro Takamori translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…