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

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

What does the TypeError: _n6.split is not a function (it is undefined) mean?

问题

  1. 我尝试过并调试了不同的方法,得出了这是问题的结论

const artistsCollectionRef = collection(db, "Artists");

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

  1. const eventRef = doc(db, "Events", eventId);
  2. if (change.type === "modified") {
  3. updateDoc(eventRef, {
  4. Artist: updatedData.Name,
  5. });
  6. }
  7. });

});

  1. 我正在使用 Firebase V10 Expo,如果这不是有帮助的话,对不起,这是我第一次在Stackoverflow上发帖。
  2. 我试图让当一个Firebase文档中的数据发生变化时,另一个文档中的数据也会发生变化,我还有更多的代码,但这段代码是问题所在。我正在使用useSnapshot来检查艺术家文档中是否发生了变化,然后它需要检查发生了什么变化,并根据变化更新事件文档。
  3. ```
  4. <details>
  5. <summary>英文:</summary>
  6. I have tried and debugged different things and came to the conclusion that this is the problem
  7. ```
  8. const artistsCollectionRef = collection(db, &quot;Artists&quot;);
  9. onSnapshot(artistsCollectionRef, (snapshot) =&gt; {
  10. snapshot.docChanges().forEach((change) =&gt; {
  11. const updatedData = change.doc.data();
  12. const eventId = updatedData.Events;
  13. const eventRef = doc(db, &quot;Events&quot;, eventId);
  14. if (change.type === &quot;modified&quot;) {
  15. updateDoc(eventRef, {
  16. Artist: updatedData.Name,
  17. });
  18. }
  19. });
  20. });

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变量存在问题,我无法确定问题出在哪里,因为它已经被定义了。但是我成功地通过以下方式解决了它:

  1. const updatedData = change.doc.data();
  2. const eventIds = updatedData.Events;
  3. if (change.type === "modified") {
  4. for (const eventId of eventIds) {
  5. const eventRef = doc(db, "Events", eventId);
  6. await updateDoc(eventRef, {
  7. Artist: updatedData.Name,
  8. });
  9. }
  10. }
英文:

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:

  1. const updatedData = change.doc.data();
  2. const eventIds = updatedData.Events;
  3. if (change.type === &quot;modified&quot;) {
  4. for (const eventId of eventIds) {
  5. const eventRef = doc(db, &quot;Events&quot;, eventId);
  6. await updateDoc(eventRef, {
  7. Artist: updatedData.Name,
  8. });
  9. }
  10. }

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:

确定