2013-03-14 4 views
1

하위 템플릿의 데이터에 어떻게 액세스합니까?하위 템플릿에 데이터 전달

App.Router.map(function() { 
    this.resource("users", function(){ 
     this.route('new'); 
    }); 
    this.resource("user", {path: '/users/:user_id'}, function(){ 
     this.route('edit'); 
    }); 
}); 

경로 :

App.UsersIndexRoute = Ember.Route.extend({ 
    model: function() { 
     return App.User.find(); 
    } 
}); 

단일 사용자 템플릿 :

<script type="text/x-handlebars" data-template-name="user"> 
    <h2>{{name_full}} is the username on the resource template</h2> 
    {{ outlet }} 
</script> 

단일 사용자 인덱스 템플릿 :

<script type="text/x-handlebars" data-template-name="user/index"> 
    <h2>{{name_full}} is the username on the index page.</h2> 
    {{#linkTo users}}Back to All Users{{/linkTo}} 
</script> 
예를 들어

그녀는 내 라우터의

단일 사용자 템플릿이 사용자 개체에 액세스하는 방법을 이해하지만 하위 경로에 어떻게 액세스 할 수 있습니까?

나는 Ember Router Guides을 방문했지만, 여전히 나에게 명확하지 않습니다.

답변

2

하위 경로 액세스 권한을 부여하려면 UsersIndexRoute를 정의하고 모델 후크에서 사용자를 반환해야합니다. 그래서 :

App.UserIndexRoute = Ember.Route.extend({ 
    model: function() { 
    return this.modelFor("user"); 
    } 
}); 

modelFor 아무것도 할 수 있지만,이 경우에는 부모가 될 일이 수 지정된 경로에 대한 현재의 모델을 조회합니다.

+0

의미가 있습니다. 고맙습니다. – user1168427

관련 문제