我正在使用Ember.js中的對象模型。我非常喜歡它,但有一件事讓我感到困惑。在Ember.js中擴展對象控制器中斷
此作品(http://emberjs.jsbin.com/jepazo/1/edit?html,css,js,console,output):
App.Car = Ember.Object.extend({
color: 'red',
brand: "Tesla",
desciption: function(){
return this.get('color') + this.get('brand');
}.property('color','brand')
})
App.IndexController = Ember.Controller.extend({
zl: [App.Car.create(), App.Car.create({brand: 'BMW'})]
})
但我不能宣佈它的控制器(http://emberjs.jsbin.com/jepazo/2/edit?html,css,js,console,output)上:
App.IndexController = Ember.Controller.extend({
car: Ember.Object.extend({
color: 'red',
brand: "Tesla",
desciption: function(){
return this.get('color') + this.get('brand');
}.property('color','brand')
}),
zl: [this.get('car').create(), this.get('car').create({brand: 'BMW'})]
)};
有誰知道爲什麼會這樣?
在你的問題中的代碼看起來是正確的,在你的提琴代碼缺少一個'}); '。 – givanse 2014-12-07 00:20:36