使用Firebase查询从ID数组中获取数据 [英] Use Firebase-query to get data from an array of ID's

查看:268
本文介绍了使用Firebase查询从ID数组中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Polymerfire的firebase-query为数组中的每个ID检索一个子列表。我有三个ID和一个firebase查询数组,如下所示:

 < firebase-query id =teamContacts 
path ={{teamConPath}}
data ={{teamConData}}>< / firebase-query>

和一些观察者看起来像:

  teamConData:{
observer:'_teamConDataChanged'
},
teamConPath:{
value:'',
observer :'_teamConPathChanged'
},

_teamConPathChanged:function(newValue,oldValue){
var self = this;
if(!app.isEmpty(newValue)){
this。$。teamContacts.getStoredValue(newValue).then((response)=> {
// self.teamConData = value ;
console.log('gsv then');
});
console.log('teamConData:',this.teamConData);
$ b $,
_teamConDataChanged:function(newValue,oldValue){
console.log('teamConChanged',newValue);
},

初始路径 teamContacts 为空。在我设置路径后,我不明白如何获取和使用数据。 Firebase文档显示了一个称为 getStoredValue()的方法,但是该方法似乎不在Github上的firebase查询源中。我认为设置一个新的路径将获取数据并触发数据的观察者,但似乎并不是这样。我怎样才能得到的firebase查询重新查询与新的路径,然后与数据异步工作?

解决方案

teamConData 这是一个对象,我将创建一个观察者,如

  observers:[ '_teamConDataObserver(teamConData。*)'],
_teamConDataObserver:function(changedData){
//对数据做
}
pre>

我会建议你看看这个polycast,它可能会有帮助。 https://youtu.be/m1hFhDYDY6o?t=4m35s


I'm trying to use Polymerfire's firebase-query to retrieve a list of children for each ID in an array. I have and array with three ID's and a firebase-query that looks like:

<firebase-query id="teamContacts"
                path= "{{teamConPath}}"
                data="{{teamConData}}"></firebase-query>

and a couple observers that look like:

teamConData: {
  observer: '_teamConDataChanged'
},
teamConPath: {
  value: '',
  observer: '_teamConPathChanged'
},

_teamConPathChanged: function(newValue, oldValue) {
  var self = this;
  if (!app.isEmpty(newValue)) {
    this.$.teamContacts.getStoredValue(newValue).then((response) => {
      // self.teamConData = value;
      console.log('in the gsv then');
    });
    console.log('teamConData: ', this.teamConData);
  }
},
_teamConDataChanged: function(newValue, oldValue) {
  console.log('teamConChanged', newValue);
},

Initially the path to teamContacts is null. After I set the path I don't understand how to get and work with the data. The Firebase documentation shows a method called getStoredValue() but that method doesn't seem to be present in the firebase-query source on Github. I thought setting a new path would fetch the data and trigger the observer for the data but that doesn't seem to be the case. How can I get the firebase-query to re-query with the new path and then asynchronously work with the data?

解决方案

As teamConData it's an object I will create an observer like

observers: ['_teamConDataObserver(teamConData.*)'],
_teamConDataObserver: function(changedData) {
    // do something with the data
}

I will recommend you to look at this polycast, it could be helpful https://youtu.be/m1hFhDYDY6o?t=4m35s

这篇关于使用Firebase查询从ID数组中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆