0

I need something like that, but i dont get the correct concatenation with the for and the push. In fact, i would like to avoid doing multiple queries, one per "palabras[i]". It would be excelent if i be able to go only one time to the database:

function ($scope, $rootScope, $stateParams, $firebaseArray) {

     var arrayRta = new Array();
     var palabras =  $rootScope.textAreaOfrecer.toLowerCase().split(' ');
      for (i = 0; i < palabras.length; i++) { 
           var elementosConI = firebase.database().ref().child("solCompras").orderByChild("palabras/" + palabras[i]).equalTo(true);

            arrayRta.push(elementosConI);
      }

   $scope.solicitudes = arrayRta;//$firebaseArray(arrayRta);


}


{
  "solCompras" : {
    "-KdTUecpbUuWJO_Fbj5Y" : {
      "palabras" : {
        "123" : true,
        "444" : true,
        "123123" : true
      },
      "post" : "123 123123 444",
      "user" : "demo"
    },
    "-KdTcRy_P0rjEpnHwHCC" : {
      "palabras" : {
        "123" : true
      },
      "post" : "123",
      "user" : "demo"
    },
Ariel Brizi
  • 41
  • 1
  • 7

1 Answers1

0

If you're looking to add the words to the list in the database, just call firebase.database().ref().child("solCompras").push(palabras[i]) for each word.

This is going to be as fast as adding them all in one call, because the requests are pipelined over the same connection. See Speed up fetching posts for my social network app by using query instead of observing a single event repeatedly

Community
  • 1
  • 1
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • I want to add it in javascript array. Not in database – Ariel Brizi Feb 22 '17 at 10:35
  • In that case, please edit your question to include the JSON (as text, no screenshot) you're trying to read. You can get this by clicking Export JSON in the [Firebase Database console](https://console.firebase.google.com/project/_/database/data/). – Frank van Puffelen Feb 22 '17 at 15:34
  • { "solCompras" : { "-KdTUecpbUuWJO_Fbj5Y" : { "palabras" : { "123" : true, "444" : true, "123123" : true }, "post" : "123 123123 444", "user" : "demo" }, "-KdTcRy_P0rjEpnHwHCC" : { "palabras" : { "123" : true }, "post" : "123", "user" : "demo" }, – Ariel Brizi Feb 23 '17 at 00:59