英文:
What does the TypeError: _n6.split is not a function (it is undefined) mean?
问题
我尝试过并调试了不同的方法,得出了这是问题的结论
const artistsCollectionRef = collection(db, "Artists");
onSnapshot(artistsCollectionRef, (snapshot) => {
snapshot.docChanges().forEach((change) => {
const updatedData = change.doc.data();
const eventId = updatedData.Events;
const eventRef = doc(db, "Events", eventId);
if (change.type === "modified") {
updateDoc(eventRef, {
Artist: updatedData.Name,
});
}
});
});
我正在使用 Firebase V10 和 Expo,如果这不是有帮助的话,对不起,这是我第一次在Stackoverflow上发帖。
我试图让当一个Firebase文档中的数据发生变化时,另一个文档中的数据也会发生变化,我还有更多的代码,但这段代码是问题所在。我正在使用useSnapshot来检查艺术家文档中是否发生了变化,然后它需要检查发生了什么变化,并根据变化更新事件文档。
```
<details>
<summary>英文:</summary>
I have tried and debugged different things and came to the conclusion that this is the problem
```
const artistsCollectionRef = collection(db, "Artists");
onSnapshot(artistsCollectionRef, (snapshot) => {
snapshot.docChanges().forEach((change) => {
const updatedData = change.doc.data();
const eventId = updatedData.Events;
const eventRef = doc(db, "Events", eventId);
if (change.type === "modified") {
updateDoc(eventRef, {
Artist: updatedData.Name,
});
}
});
});
I'm using Firebase V10 and Expo, sorry if this isn't helpful it's my first time posing on Stackoverflow.
I tried to make it so that when data changes in one Firebase document it also changes in another document, I have more code for this but this code is the problem. I'm using useSnapshot to check when a change is made in the artists document, then it needs to check what changed and update the event document based off of what changed
答案1
得分: 0
对eventRef变量存在问题,我无法确定问题出在哪里,因为它已经被定义了。但是我成功地通过以下方式解决了它:
const updatedData = change.doc.data();
const eventIds = updatedData.Events;
if (change.type === "modified") {
for (const eventId of eventIds) {
const eventRef = doc(db, "Events", eventId);
await updateDoc(eventRef, {
Artist: updatedData.Name,
});
}
}
英文:
There was an issue with the eventRef variable, I can't figure out what it was because it was defined. But i managed to work around it by doing this:
const updatedData = change.doc.data();
const eventIds = updatedData.Events;
if (change.type === "modified") {
for (const eventId of eventIds) {
const eventRef = doc(db, "Events", eventId);
await updateDoc(eventRef, {
Artist: updatedData.Name,
});
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论