2013-02-15 2 views
1

컨트롤러 모델을 올바르게 설정하는 방법은 무엇입니까? 엠버 1.0.0-pre4를 :Ember js DS.FixtureAdapter를 사용하여 컨트롤러의 모델을 설정하는 방법은 무엇입니까?

<script> 
    window.App = Ember.Application.create(); 

    App.Store = DS.Store.extend({ 
    revision: 11, 
    adapter: 'DS.FixtureAdapter' 
    }); 

    App.ApplicationRoute = Ember.Route.extend({ 
    setupController: function() { 
    this.controllerFor('topic').set('model', App.Topic.find()); 
    } 
    }); 

    App.Topic = DS.Model.extend({ 
    label: DS.attr('string'), 
    selected: DS.attr('boolean') 
    }); 

    App.Topic.FIXTURES = [ 
    { id: 1, label: '1. First topic', selected: true }, 
    { id: 2, label: '2. Second topic' }, 
    { id: 3, label: '3. Third topic' }, 
    ]; 

    App.TopicController = Ember.ArrayController.extend(); 

    App.IndexController = Ember.ObjectController.extend({ 
    content: [], 
    test: 'INDEX TEST', 
    currentTopics: null 
    }); 
</script> 

템플릿

<script type="text/x-handlebars" data-template-name="index"> 

    {{view Ember.Select 
    contentBinding="App.TopicController" 
    selectionBinding="currentTopics" 
    optionLabelPath="content.label" 
    optionValuePath="content.id"}} 

</script> 

버전 (Ember.Select보기로 TopicController를 결합하려고) : 여기

내 코드 (지고 오류가)입니다 엠버 데이터 수정본 11

JsFiddle

답변

4

here에 대해 계속 토론있다, 그러나 지금 현재로, 엠버 컨트롤러 model의 별칭 content를 사용하므로 setupController은 다음과 같아야합니다

App.ApplicationRoute = Ember.Route.extend({ 
    setupController: function() { 
    this.controllerFor('topic').set('content', App.Topic.find()); 
    } 
}); 

을 또한 this sample fiddle을 확인할 수 FixtureAdapter을 사용합니다. 이 작업이 진행 중임을 명심하십시오. 시간을 찾으면 업데이트 할 것입니다.

http://jsfiddle.net/schawaska/KjWKw/

+0

감사합니다. 나는 'content'로 바뀌었고 괜찮아 보이지만 여전히 Ember.Select를보기 위해 contentBinding을 추가하는 방법을 알아낼 수 없습니다. 나는 이것을 시도했다 '{{보기 Ember.Select' 'contentBinding = "App.TopicController.content"'_Uncaught 오류 : 어설 션 실패 : 정의되지 않은 개체에 '길이'로 get을 호출 할 수 없습니다 ._ – FoREacH

+0

설정 시도 단순히'content' (또는'view.content')입니다. 나는 당신이 바인딩을 설정하는 방법이 언젠가는 더 이상 사용되지 않을 것이라고 생각한다. – MilkyWayJoe

+2

나는 완전히 불쾌한 날을 보내서 엠버 데이터를 작동 시키려고 노력했다. 그리고이 버전의 마침내 내 애플 리케이션이 작동했다. 고마워! – Ben

관련 문제