如何在Ember.js(1.0)中创建自定义视图类和绑定属性? 像这样:
SomeClass = Ember.View.extend
someProp: true
createChildView: ->
OtherView.create
somePropBinding: 'this.someProp'
答案 0 :(得分:0)
使用parentView
访问parentView
的属性应该有效:
示例:
App.MyView = Ember.ContainerView.extend({
someProp: true,
didInsertElement: function() {
var viewClass = App.SomeView.create();
this.pushObject(viewClass);
}
});
然后您可以使用Ember.computed.alias('...)
创建绑定:
App.SomeView = Ember.View.extend({
anotherProp: Ember.computed.alias('parentView.someProp'),
didInsertElement: function() {
console.log('anotherProp: '+this.get('anotherProp'));
}
});
抱歉没有coffescriptiying代码:)
工作example。
希望它有所帮助。