javascriptfirebasefirebase-realtime-databasepolymer-1.0polymerfire

Polymer Firebase. Arrays in Objects


Im using polymer and firebase and I was wondering how to create an array of objects inside an object.

Like the object above

I want nested data like in the object the groups single object whereby we have members and the names inside it

      this.$.query.ref.push({
        name: this.$.crewName.value,
        description: this.$.crewDescription.value,
        createddate: new Date().toString(),
        creator: this.$.createcrewlogin.user.uid,
        slug: sluggedname
      });

With a simple push method like this .How do I achieve that


Solution

  • When you write to the Firebase Database from JavaScript, you pass in a standard JSON object. This means that you can just nest the objects inside the object you pass to push():

      this.$.query.ref.push({
        name: this.$.crewName.value,
        description: this.$.crewDescription.value,
        createddate: new Date().toString(),
        creator: this.$.createcrewlogin.user.uid,
        slug: sluggedname,
        subobject: {
          techpioneers: true,
          womentechmakers: true
        }
      });