2013-10-23 7 views
2

어레이 컨트롤러 변수에 액세스 할 수 없습니다. 내가 예를 들어,이 간단한 응용 프로그램이 있습니다Ember.js 컨트롤러가 작동하지 않습니다.

App.js

App = Ember.Application.create(); 

App.ApplicationAdapter = DS.FixtureAdapter.extend(); 

App.Router.map(function() { 
    this.route('hello'); 
}); 

App.IndexRoute = Ember.Route.extend({ 
     redirect: function() { 
     this.transitionTo('hello'); 
     } 
}); 

App.HelloController = Ember.ArrayController.extend({ 
    name: 'tom' 
}); 

App.HelloRoute = Ember.Route.extend({ 
    model: function() { 
      return this.store.find('hello'); 
    } 
}); 

App.Hello = DS.Model.extend({ 
    title: DS.attr('string') 
}); 

App.Hello.FIXTURES = [{ 
    id: 1, 
    title: 'hello' 
},{ 
    id: 2, 
    title: 'hello' 
}]; 

을 내 견해는 다음과 같습니다 : 나는이 코드를 저장할 때

<script type="text/x-handlebars" data-template-name="application"> 
<h2>Welcome to Ember.js</h2> 

{{outlet}} 
</script> 


<script type="text/x-handlebars" data-template-name="hello"> 
    {{#each}} 
    {{title}} {{name}} 
    {{/each}} 
</script> 

페이지가 그냥 "안녕하세요", "안녕하세요"렌더링 나는 "hello tom" "hello tom"을 기대한다. 내가 뭘 잘못하고있어?

도움주세요.

답변

2

문제는 각 구문의 컨텍스트를 모델로 변경하여 더 이상 컨텍스트에 이름이 없기 때문입니다.

http://emberjs.jsbin.com/UzUxIwa/1/edit

솔직히
<script type="text/x-handlebars" data-template-name="hello"> 
    {{#each item in controller}} 
    {{item.title}} {{controller.name}} 
    {{/each}} 
</script> 

이것보다 더 나은는 ItemController의를 사용하고,

http://emberjs.jsbin.com/UzUxIwa/2/edit

App.HelloController = Ember.ArrayController.extend({ 
    itemController:'singleHello' 
}); 

App.SingleHelloController = Ember.ObjectController.extend({ 
    name: 'tom' 
}); 

{{#each item in controller}} 
    {{item.title}} {{item.name}}</br> 
{{/each}} 
+0

이 작동 해당 컨트롤러에 감사 속성을 넣어하는 것입니다! – cmszc

관련 문제