【发布时间】:2019-02-14 14:21:15
【问题描述】:
我收到以下错误:
undefined 不是对象(评估 'item.id')
我有这个。获取项目和删除项目:
getItems = async () => {
this.setState({ refreshing: true });
this.unsubscribe = await this.ref.onSnapshot((querySnapshot) => {
const todos = [];
querySnapshot.forEach((doc) => {
todos.push({
id: doc.id,
tips: doc.data().tips,
date: doc.data().date,
user: doc.data().user,
like: doc.data().like,
})
this.ref.get().then(function(documentSnapshot) {
// check and do something with the data here.
});
})
this.setState({
refreshing: false,
getData: todos
})
})
}
deletePost({ item, index }){
var deleteItemId = item.id;
firestore.collection("tips").doc(deleteItemId).delete().then(function() {
alert("deleted", deleteItemId)
}).catch(function(error) {
alert("Error removing document: ", error);
});
}
渲染的项目如:
renderItem = ({ item, index }) => {
return (
<Text onPress={() => this.deletePost(item.id)}>Delete</Text>
)
}
这是 item.id 就像NnX57tSpqvPvIUN7tRY4
【问题讨论】:
-
sdfsifh是字符串。 -
你检查过类型吗?似乎是一个字符串
-
嗯,添加了我得到的错误。未定义
-
不,输出是“NnX57tSpqvPvIUN7tRY4”和“iIRTop4TKOBdL5o6dIO3”
标签: javascript reactjs react-native