0

This function will be loop and every loop key1 and key2 will change... the problem is the database results which is an array will not get every data of the keys it will only record the last data.

GettingData: function(key1,key2){
       var list=[];
       console.log('Getting Data of '+key2);
       var ref = firebase.database().ref('/users/'+key1+'/products/'+key2).orderByKey().equalTo('name');
       ref.on('child_added', function(data) {
       console.log(data.val());
       list.unshift(data.val());
       this.databaseresult = list;
       console.log('Productdata of '+ key1 +' is LOADED');
       console.log('pushing to array '+list);
       console.log(this.databaseresult);
       this.$.results.products = this.databaseresult;
       }.bind(this));
       },
ArK
  • 20,698
  • 67
  • 109
  • 136

1 Answers1

0

When changing properties if you want any observers to be notified use this.set('propertyName', value);. Also when your setting this.$.results.products = this.databaseresult; with your current code nothing will update plus even if using Polymer.set method you won't be the data binding I think your expecting because that requires the use of the polymer data binding syntax IE <x-element products="{{databaseresult}}"></x-element>. At least to my knowledge, you might be able to force it manually. by calling a this.fire('databaseresult-changed'); event.

GettingData: function(key1,key2){
  console.log('Getting Data of '+key2);
  var ref = firebase.database().ref('/users/'+key1+'/products/'+key2).orderByKey().equalTo('name');
  ref.on('child_added', function(data) {
    console.log('pushing value' + data.val() + 'to ' + this.databaseresult);
    this.push('databaseresult', data.val());
    console.log('Productdata of '+ key1 +' is LOADED');
  }.bind(this));
},

 <!-- One way binding -->
 <x-element id="results" products="[[databaseresults]]"></x-element>

 <!-- Two way binding -->
 <x-element id="results" products="{{databaseresults}}"></x-element>
Snewedon
  • 2,410
  • 2
  • 13
  • 27