2013-11-01 3 views
1

나는 가이드와 인터넷을 둘러싼 몇 가지 질문을 해왔다. 이것은 간단해야하지만 나는 뭔가를 놓친 것입니다. 최악의 경우 다른 것들은 훌륭하지만 너무 사소한 것이 아닙니다.Ember.js - IndexRoute의 모델

기본 Ember 앱을 설정했습니다. 방문 페이지로 색인 템플릿이 정의되어 있습니다. 내가 스크립트에서 자바 스크립트 객체로 가지고있는 '모델'로부터 바로 박쥐를 참조하기를 원하는 요소가 있습니다. 내 HTML에서

var company = { 
    id: '1', 
    name: 'Some Inc.', 
    email: '[email protected]' 
}; 

App.IndexRoute = Ember.Route.extend({ 
    setupController: function(controller, company) { 
    // Set the IndexController's `title` 
    controller.set('title', "Publisher Dashboard"); 
    controller.set('model', company); 
    } 
}); 

나는 인덱스 템플릿 내에서 가지고 가지 버전에 비해 변경된 경우

<script type="text/x-handlebars" data-template-name="index"> 
... 
    <span class="name">{{name}} ({{email}})</span> 

는 모르겠어요. 나는 같은 구문을 수행하는 다른 문법을 보았다. 나는 v1.0.0을 사용하고있다.

답변

0

당신은 당신이 IndexRoute

App.IndexRoute = Ember.Route.extend({ 
    model: function() { 
    return 'SOMETHING' //could be 'company' 
    }, 
    setupController: function(controller, company) { 
    // Set the IndexController's `title` 
    controller.set('title', "Publisher Dashboard"); 
    controller.set('model', company); 
    } 
}); 

SetupController 모델에 사용하려는 모델을 선언해야하는 경로에 모델 후크에 의해 반환되는 모델을 사용합니다. 따라서 모델 후크에서 '회사'를 반환하면됩니다. 해당 회사 개체에 액세스 할 수 있습니다.

+0

감사합니다. Rick! 실제로 그것은 당신과 @ 환타의 답변의 조합이었습니다. – zacharykane

+0

정말 대단합니다. 코드를 작동시키는 것이 전부입니다. 해피 코딩! – elrick

0

시도해 보셨습니까?

setupController: function(controller, company) { 
    this._super(controller, model); 
    // Set the IndexController's `title` 
    controller.set('title', "Publisher Dashboard"); 
    controller.set('model', company); 
} 

슈퍼를 불러오는 한 줄을 추가했습니다.

+0

감사합니다! 실제로 그것은 당신과 릭의 대답의 조합 이었지만. – zacharykane