下面我提供了一个我认为应该起作用的例子,但没有.我的期望是,如果控制器继承自另一个控制器,那么它应该能够访问父类中提供的行为.我知道"需求"可以实现相同的行为,但我认为如果你能继承行为会更加清晰.
你也可以使用mixin.这是什么?它是一种多重继承.
App.Important = Ember.Mixin.create({
sharedBehavior: function() {
return "A winner is you!!!";
}.property()
});
App.OtherImportant = Ember.Mixin.create({
otherSharedBehavior: function() {
return "A winner is not you!!!";
}.property()
});
App.AnotherController = Ember.controller.extend(App.Important, App.OtherImportant, {
importantStuff: function() {
var ohBeehave = this.get("sharedBehavior");
if(ohBeehave) {
return ohBeehave;
} else {
return "FML";
}
}.property("sharedBehavior")
});
Run Code Online (Sandbox Code Playgroud)
请参见http://emberjs.com/api/classes/Ember.Mixin.html
| 归档时间: |
|
| 查看次数: |
1683 次 |
| 最近记录: |