2014-12-07 4 views
0

현재 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'})] 
)}; 

사람이 알고 있나요

?

+0

, 당신의 바이올린의 코드가 누락을 앞에'}); '. – givanse

답변

3

배열 선언의 "this"가 Window 객체이기 때문입니다.

zl을 배열을 반환하는 computedProperty로 변환하면 작동합니다. 같은

뭔가 : 여기

zl: function() { 
     return [this.get('car').create(), this.get('car').create({ brand: 'BMW'})]; 
    }.property() 

이 문제 나타낸 jsbin입니다 :

http://emberjs.jsbin.com/fudiruduxa/1/edit?html,css,js,output

질문의 코드는 올바른 보이는
+0

물론 이치에 맞습니다. 당신의 도움을 주셔서 감사합니다 :) – Paul

관련 문제