【发布时间】:2020-01-02 11:43:08
【问题描述】:
我正在使用此代码从 React Native 中的 Array 中删除一个项目:
var array = [...this.state.gallery];
if (index !== -1) {
array.splice(index, 1);
this.setState({gallery: array,
photosHaveNow: this.state.photosHaveNow - 1});
}
但是,当项目被删除时,该数组将写入您的位置:
{"empty": true, "key": "blank-2"}
最后一个例子:
["http://parquedasfeiras.online/wp-content/uploads/2019/09/WhatsApp-Image-2019-11-30-at-00.38.33.jpeg", "http://parquedasfeiras.online/wp-content/uploads/2019/09/WhatsApp-Image-2019-11-30-at-00.38.33-1.jpeg", "http://parquedasfeiras.online/wp-content/uploads/2019/09/WhatsApp-Image-2019-11-30-at-00.38.33-2.jpeg", "http://parquedasfeiras.online/wp-content/uploads/2019/09/WhatsApp-Image-2019-11-30-at-00.38.33-3.jpeg", "http://parquedasfeiras.online/wp-content/uploads/2019/09/WhatsApp-Image-2019-11-30-at-00.38.34.jpeg", "http://parquedasfeiras.online/wp-content/uploads/2019/09/WhatsApp-Image-2019-11-30-at-00.38.34-1.jpeg", "http://parquedasfeiras.online/wp-content/uploads/2019/09/WhatsApp-Image-2019-11-30-at-00.38.34-4.jpeg", {"empty": true, "key": "blank-2"}, {"empty": true, "key": "blank-2"}, {"empty": true, "key": "blank-2"}, {"empty": true, "key": "blank-2"}, {"empty": true, "key": "blank-2"}]
当通过拼接移除一个项目时,“{”empty“:true,”key“:”blank-2“}”放置到位,我希望什么都没有放置。
【问题讨论】:
-
问题不清楚。你想用那个对象替换删除的项目吗?或其他任何东西。请清楚地编辑问题。提供要处理的数据。
-
你好,抱歉当通过拼接移除一个项目时,"{" empty ": true," key ":" blank-2 "}" 放置到位,我希望什么都没有放入地点。
标签: javascript reactjs react-native