[英]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.