2 回答
TA贡献1848条经验 获得超6个赞
我找到了我的答案,所以如果有人遇到同样的问题,这里是代码:
`deleteNote = (index) => {
console.log(index)
let arr = this.state.noteList;
delete arr[index]
this.setState({
activeCounter: Number(this.state.activeCounter - 1)
})
}`
这是我的映射代码:
`this.state.noteList.map((item,index) =>
<View style={styles.createBox}>
<View style={{flex:4,justifyContent: 'center',backgroundColor:
"lightpink",}}>
<Text style={{textAlign:'center',fontSize:deviceWidth/20,}}>
{item.trim()}
</Text>
</View>
<TouchableOpacity key={index} onPress={() => this.deleteNote(index)} style={{flex:1,justifyContent: 'center'}}>
<AntDesign name="checkcircleo" style={{alignSelf:'center',backgroundColor: "#e6a25c"}} size={deviceWidth/5} color="black" />
</TouchableOpacity>
)`
我希望这有帮助。这实际上花了我 1 周的时间才弄清楚,最后我弄明白了。
TA贡献1777条经验 获得超10个赞
尝试这个:
removeList = (item) => {
let val = this.state.noteList;
let arr;
for (let i = 0; i < val.length; i++) {
if (val[i] === item) {
arr = val.splice(i, 1);
}
}
let complete = this.state.completedTask;
complete.push(arr);
};
添加回答
举报