2013-11-04 3 views
0

방금 ​​Ember로 시작하여 기본적인 웹 앱 구조를 갖추 었습니다. 부분 템플릿을 설정하고 테스트 데이터를 가져 오려고합니다. 내 '집'템플릿을 사용하면 테스트 데이터를 볼 수 있지만 내 컬렉션의 부분 템플릿에는 가져올 수 없습니다. 나는 거의 친숙하지 않은 Ember의 기본 개념과 관련이 있어야한다는 것은 거의 확실합니다. 여기 내 간단한 HTML 및 아래 Ember js입니다. 누군가가 내 부분 '컬렉션'템플릿에 '집'템플릿에서 '각'루프를 가져올 수있는 방법 어떤 생각을 가지고 있다면, 나는 매우 감사 할 것 : 여기Ember - 조명기 데이터가 포함 된 부분 템플릿

[code] 
<script type="text/x-handlebars" ><!-- data-template-name="application" --> 
    <div id="main"> 
     <ul> 
      <li> 
       <image src="logo.png" style="width:439px;height:102px;"/> 
      </li> 
      <li>{{#link-to 'home'}}Home{{/link-to}} | {{#link-to 'help'}}Help{{/link-to}}</li> 
     </ul> 
    </div> 

    <div class="collections"> 
     {{partial 'collections'}} 
    </div> 

    <div class="statistics"> 
     {{outlet}} 
    </div>   
    </script> 

    <script type="text/x-handlebars" id="collections"> 
     COLLECTIONS<br/> 
     <!-- here is where I wand the 'each' loop to go --> 
    </script> 

    <script type="text/x-handlebars" id="home"> 
     OnLoad : This is Home Page<br/>    
     <ul> 
      {{#each}} 
       <li> 
       <label>{{title}}</label> 
       </li> 
      {{/each}} 
     </ul>   
    </script> 

    <script type="text/x-handlebars" id="help"> 
     Welcome to Help Page 
    </script> 
[/code] 

그리고 것은 위의 대한 JS 코드입니다 : [코드] App = Ember.Application.create();

App.Router.map(function(){ 
    this.resource('home', { path: '/' }); 
    this.resource('help');  
}); 

App.CollectionsRoute = Ember.Route.extend({ 
    model: function(){ 
     return items; 
    } 
}); 

App.HomeRoute = Ember.Route.extend({ 
    model: function(){ 
     return items; 
    } 
}); 
var items = [ 
    { 
    id: 1, 
    title: 'Item 1', 
    belongsTo: 'parent path 1' 
    },{ 
    id: 2, 
    title: 'Item 2', 
    belongsTo: 'parent path 2' 
    },{ 
    id: 3, 
    title: 'Item 3', 
    belongsTo: 'parent path 3' 
    } 
]; 

[/code] 

답변

0

partial 'collections'에는 응용 프로그램 템플리트와 동일한 컨텍스트가 있습니다. 그래서 만약 당신이 선언

App.ApplicationRoute = Ember.Route.extend({ 
    model: function(){ 
     return items; 
    } 
}); 

가 사용할 수 있습니다 :

<script type="text/x-handlebars" id="collections"> 
    COLLECTIONS<br/> 
    <ul> 
     {{#each}} 
      <li> 
      <label>{{title}}</label> 
      </li> 
     {{/each}} 
    </ul> 
</script> 
+0

예! Marcio에게 감사드립니다. – user2917629

관련 문제