1

我想搜索我的 firebase 数据库,以便用户能够找到他们正在搜索的产品。

目前,我正在将数据属性 this.searchText 与 firebase 中的 product.title 匹配。

return str.filter((product) => {
    return product.title.match(textSearch)
})

我对此有疑问:

如果数据库包含 1000 个产品,则过滤站点上的产品没有意义,而是进行有效的查询,例如:

firebase.database.ref('products').containing('leather shoe')

我只是找不到合适的解决方案。

4

1 回答 1

0

Firebase.database.ref('products') 返回一个参考,并且没有参考的containing()方法。

最相似的方法是equalTo()这里详述。

如果保存值“皮鞋”的字段是“类型”字段,您可以执行以下操作:

var ref = firebase.database().ref("products");
ref.orderByChild("type").equalTo("leather shoe").on("child_added", function(snapshot) {
  console.log(snapshot.key);
});

使用 vuefire,您可以:

var firebaseApp = firebase.initializeApp({ ... })
var db = firebaseApp.database()

var vm = new Vue({
  el: '#demo',
  firebase: 
    anArray: db.ref("products").orderByChild("type").equalTo("leather shoe")
  }
})
于 2018-08-02T12:35:41.327 回答