Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

252
Views
FirebaseError: función DocumentReference.update() llamada con datos no válidos. Las matrices anidadas no son compatibles

ingrese la descripción de la imagen aquí . ingrese la descripción de la imagen aquí Estoy tratando de implementar la función de agregar al carrito con mi base de fuego usando firestore.

Tengo una función de búsqueda que obtiene cualquier artículo existente que ya esté en el carrito. Pero todo lo que necesito es el valor en los elementos de la matriz, pero cuando lo agrego a mi lista fectchedcartItems, crea una matriz anidada que me genera problemas cuando intento actualizar el carrito, ya que no es compatible con la matriz anidada. ¿Hay alguna manera de obtener los valores y no crear una matriz anidada? buscar elementos = () => {

 Fire.shared.firestore.collection("cart").where("userId", "==", this.state.uid).get().then((qSnap) => { let itemList = [] qSnap.docs.forEach(item => { itemList.push(item.data().items) this.setState({ fetchedcartItems: itemList }) }) console.log("fectched product", this.state.fetchedcartItems); }); } addItemToCart = () => { this.fetchItems() let items = this.state.fetchedcartItems items.push({ item: this.state.name, userId: this.state.uid }) this.setState({ items: items, fectchingitemsloading: true, }, () => Fire.shared .firestore .collection('cart') .doc(this.state.cartId) .update({ items: items }) .then(() => this.fetchItems()) ) }
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

let itemList = [] qSnap.docs.forEach(item => { itemList.push(item.data().items) this.setState({ fetchedcartItems: itemList }) })

item.date().items parece ser una matriz. Entonces, cuando inserta una matriz en otra matriz, obtiene una matriz anidada. En su lugar, debe insertar los elementos individuales en la matriz para que termine con una sola matriz de nivel superior:

 let itemList = []; qSnap.docs.forEach(item => { itemList.push(...item.data().items) // <---- added spread syntax }) // Moved the setState outside the loop; there's no need to set state multiple times this.setState({ fetchedcartItems: itemList })

O una alternativa usando flatMap :

 let itemList = qSnap.docs.flatMap(item => item.data().items); this.setState({ fetchedcartItems: itemList })
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!