Using a collection of polymers to create a bomb to nudge a new doc

I have a problem understanding how to insert a new document into firebase. I checked the documentation here which links to a method called add (data), however I really don't know how to use it (as my Polymer skills are still basic). Can anyone demonstrate how to push a new document by extending the item sample below.

<dom-module id="my-position">
  <template>
    <firebase-collection 
                        location="my-firebase-app.firebaseio.com/positions">
    </firebase-collection>

    <template > 
      <input is="iron-input" bind-value="{{value}}"
      placeholder="Your name here...">
    </template>
  </template>
</dom-module>

      

+3


source to share


3 answers


Use firebase-document and data binding "pushes" the object to firebase.

https://elements.polymer-project.org/elements/firebase-element?active=firebase-document



Example

+2


source


This is a very simple example to show you how to do this. It is based on the information provided in this video (although using polymer 0.5, the concepts are very similar).



<dom-module id="my-elem">
  <template>
    <firebase-collection id="ref"
      location="https://my-firbase-app/positions/">
    </firebase-collection>

    <form id="createPosition">
      <input is="iron-input" bind-value="{{name}}" type="" id="name" placeholder="name here...">
    </form>

    <paper-button on-click="submitPosition">submit</paper-button>
  </template>

  <script>
    (function () {
      Polymer({
        is: 'my-elem',
        computePositionObj: function(){
          return {
            name: this.name
          };
        },
        properties: {
          position: {
            type: Object,
            computed: 'computePositionObj(name)'
          },
          name: {
            type: String,
            value: '',
          }
        },
        submitPosition: function() {
          this.$.ref.add(this.position);
        }
      });
    })();
  </script>
</dom-module>

      

+1


source


To add an object to a location. (I keep the 'ref' reference for the next part)

      var ref = this.$.sparks.add(
        {
          content: 'Hello there',
          by: 'john'
        });

      

Add only key to location is your collection

location="https://<app-name>.firebaseio.com/message/{{id}}"

      

If you want to add a key as a child, just do

this.id = ref.key();
this.$.COLLECTIONID.query.ref().set(true);

      

0


source







All Articles