![](/img/trans.png)
[英]Ember.View.reopen() for binding data-* attribute doesn't work any longer since I updated ember version to 1.13.3
[英]How do you assign a static data- attribute to an ember view?
我需要为Ember.View分配一个静态数据属性,如何在View对象而不是{{view }}
标签中设置它。
App.MessagesFormView = Ember.View.extend({
tagName: 'div',
classNames: ['modal', 'fade'],
didInsertElement: function() {
this.$().modal('show')
},
willDestroyElement: function() {
this.$().modal('hide')
},
})
不幸的是,我没有足够的声誉来评论Ola的答案,但我认为更好的方法是不使用字符串(引号中的文本)来表示数据属性属性名称。 相反,在camelCase中编写属性名称,Ember会自动将其绑定到带连字符的属性绑定。 例如:
App.MessagesFormView = Ember.View.extend({
tagName: 'div',
attributeBindings: ['data-backdrop'],
dataBackdrop: 'static', // Binds to data-backdrop. Awesome!
});
我希望这是有道理的!
这必须使用attributeBindings
绑定和data-backdrop
或data-whatever
Ember.View对象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')
},
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.