How to assign a static data attribute to an ember view?

I need to assign a static data attribute to Ember.View, how to set this in the view, and not in the tag {{view }}.

App.MessagesFormView = Ember.View.extend({
  tagName: 'div',
  classNames: ['modal', 'fade'],
  didInsertElement: function() {
    this.$().modal('show')
  },
  willDestroyElement: function() {
    this.$().modal('hide')
  },
})
+5
source share
2 answers

Unfortunately, I do not have enough reputation to comment on Ola's answer, but I believe that a slightly better way to do this is to not use a string (quoted text) to denote the name of a data attribute property. Instead, write your property name in camelCase, and Ember will automatically bind it to the attribute's portable attribute. For instance:

App.MessagesFormView = Ember.View.extend({
  tagName: 'div',
  attributeBindings: ['data-backdrop'], 
  dataBackdrop: 'static', // Binds to data-backdrop. Awesome!
});

Hope this makes sense!

+6
source

, attributeBindings data-backdrop data-whatever Ember.View.

App.MessagesFormView = Ember.View.extend({
  tagName: 'div',
  classNames: ['modal', 'fade'],
  // Set a data attribute, of a view, requires both an attribute binding and
  // an attribute assignment
  attributeBindings: ['data-backdrop'],
  'data-backdrop': 'static',
  didInsertElement: function() {
    this.$().modal('show')
  },
  willDestroyElement: function() {
    this.$().modal('hide')
  },
})
+4

All Articles