我尝试在两个View之间使用attributeBindings进行继承。

(function(exports) {
Ember.MobileBaseView = Ember.View.extend({
    attributeBindings:['data-role', 'data-theme'],
    'data-theme': 'a'
});
})({});


(function(exports) {
Ember.ToolbarBaseView = Ember.MobileBaseView.extend({
    attributeBindings:this.get('attributeBindings').concat(['data-position']),
    'data-position': function() {

我尝试过this.get('attributeBindings')。concat(['data-position'])和Ember.MobileBaseView.get('attributeBindings')。concat(['data-position'])和Ember.MobileBaseView.attributeBindings .concat(['数据位置'])

也许,我应该只做attributeBindings:[['data-role','data-theme','data-position']],但是我宁愿找到一个更好的解决方案。

最佳答案

Ember.View#attributeBindingsconcatenated property,这意味着如果您在子类中覆盖它,则会将父类(super class)中的值连接在一起。如此有效,请参见http://jsfiddle.net/pangratz666/r72dz/:

Ember.MobileBaseView = Ember.View.extend({
    attributeBindings: ['data-role', 'data-theme'],
    'data-theme': 'a'
});


Ember.ToolbarBaseView = Ember.MobileBaseView.extend({
    attributeBindings: ['data-position']
});​

关于javascript - 使用emberjs,如何从父 View 扩展attributeBindings参数?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9906240/

10-09 20:43