Ola*_*erg 5 custom-data-attribute ember.js
我需要为Ember.View分配一个静态数据属性,如何在View对象中而不是在{{view }}标签中设置它.
App.MessagesFormView = Ember.View.extend({
tagName: 'div',
classNames: ['modal', 'fade'],
didInsertElement: function() {
this.$().modal('show')
},
willDestroyElement: function() {
this.$().modal('hide')
},
})
Run Code Online (Sandbox Code Playgroud)
不幸的是,我没有足够的声誉来评论Ola的答案,但我认为更好的方法是不使用字符串(引号中的文本)来表示数据属性属性名称.相反,在camelCase中编写属性名称,Ember会自动将其绑定到带连字符的属性绑定.例如:
App.MessagesFormView = Ember.View.extend({
tagName: 'div',
attributeBindings: ['data-backdrop'],
dataBackdrop: 'static', // Binds to data-backdrop. Awesome!
});
Run Code Online (Sandbox Code Playgroud)
我希望这是有道理的!
这必须使用Ember.View 对象的attributeBindings和data-backdrop或属性来完成。data-whatever
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')
},
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2665 次 |
| 最近记录: |