【问题标题】:Undefined array in Vuex payload using firestore where ' in ' queryVuex有效负载中的未定义数组使用firestore where'in'查询
【发布时间】:2020-10-12 11:33:49
【问题描述】:

我正在尝试进行这样的 'in' 查询:db.collection('units').where('SuperID', 'in', payload)

SuperID:是一个数字

payload:是与 SuperID 匹配的数字数组

我这样做是为了可以根据这样的文档对用户进行分组

Vuex 商店

getgs: firestoreAction(({ bindFirestoreRef, payload }) => {
      //return the promise returned by 'bindFirestoreRef'
      return bindFirestoreRef('gs', db.collection('units').where('SuperID', 'in', payload))
    }), 

方法

methods: {
    ...mapActions(['getgs']),

  ggs(payload){

      console.log(payload)

      this.getgs(payload)
  }
}

每当我尝试调用它时,它都会记录我需要的数组,然后说它未定义并引发 Firebase 错误。

【问题讨论】:

    标签: firebase vue.js google-cloud-firestore vuex vuexfire


    【解决方案1】:

    好的,这次我想我找到了答案。

    使用docs中的这个例子:

    actions: {
      checkout ({ commit, state }, products) {
        // save the items currently in the cart
        const savedCartItems = [...state.cart.added]
        // send out checkout request, and optimistically
        // clear the cart
        commit(types.CHECKOUT_REQUEST)
        // the shop API accepts a success callback and a failure callback
        shop.buyProducts(
          products,
          // handle success
          () => commit(types.CHECKOUT_SUCCESS),
          // handle failure
          () => commit(types.CHECKOUT_FAILURE, savedCartItems)
        )
      }
    }
    

    看起来你的动作定义应该是

    getgs: firestoreAction(({ bindFirestoreRef }, payload) => {
          //return the promise returned by 'bindFirestoreRef'
          return bindFirestoreRef('gs', db.collection('units').where('SuperID', 'in', payload))
        }), 
    

    使用上下文对象之外的有效负载。

    【讨论】:

    • 遗憾的是它没有用。我希望我忽略了像这样的小东西。
    • 谢谢.. 太奇怪了,因为我使用 firestoreAction(({ bindFirestoreRef, state }) => { 有 0 个问题
    • 酷,很高兴我能帮上忙!
    猜你喜欢
    • 2020-06-08
    • 1970-01-01
    • 2014-12-19
    • 1970-01-01
    • 1970-01-01
    • 2019-01-23
    • 1970-01-01
    • 2020-01-23
    • 2018-01-05
    相关资源
    最近更新 更多