TypeError: _n6.split is not a function (it is undefined) 的意思是什么?

huangapple go评论108阅读模式
英文:

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, &quot;Artists&quot;);

  onSnapshot(artistsCollectionRef, (snapshot) =&gt; {
    snapshot.docChanges().forEach((change) =&gt; {
      const updatedData = change.doc.data();
      const eventId = updatedData.Events;

      const eventRef = doc(db, &quot;Events&quot;, eventId);
      if (change.type === &quot;modified&quot;) {
        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 === &quot;modified&quot;) {
        for (const eventId of eventIds) {
          const eventRef = doc(db, &quot;Events&quot;, eventId);
          await updateDoc(eventRef, {
            Artist: updatedData.Name,
          });
        }
      }

huangapple
  • 本文由 发表于 2023年8月11日 01:33:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76878082.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定