mercredi 7 septembre 2016

Ember.js: how can I find all bindings for a component without knowing the model and properties

How can I find all bindings for a given component at runtime. Like in example below, I would like to get the attribute name ('value') and the bound model property ('model.firstName') either from the route or controller.

Example: Html

<script type="text/x-handlebars" data-template-name="index">
<x-input label="Name" value=></x-input>
</script>

JS

var App = Ember.Application.create({});

App.Person = Ember.Object.extend({
  firstName: null,
  lastName: null,
  fullName: Ember.computed('firstName', 'lastName', function() {
    return (this.get('firstName') + ' ' + this.get('lastName')).trim();
  })
});

App.IndexRoute = Ember.Route.extend({
  person: null,
  model: function () {
    if(!this.person) {
      this.person = App.Person.create({
        firstName: '',
        lastName: ''
      })
    }
    return this.person;
  },
  actions: {}
});

I am trying to use webcomponents and not ember components (). One way data-binding works for the above example, but I am trying to figure out if I can wire two way databinding to this. I am very new to ember and wanted some pointers if there is an API to get all existing bindings for a component.




Aucun commentaire:

Enregistrer un commentaire