2013-05-09 3 views
0
App.Exam = DS.Model.extend({ 
examType: attr('string'), 
examDate: attr('date'), 
gradeText: attr('string'), 
courseName: attr('string'), 
courseName__startswith: attr('string'), 
typeName: attr('string'), 
numberOf: attr('number'), 
grade: attr('number'), }); 

여기 컨트롤러에서 액세스하려는 모델입니다. 나는이컨트롤러에서 검색 결과 가져 오기

App.ExamController = Ember.Controller.extend({ 
    // the initial value of the `search` property 
    search: '' 

    ,query: function() { 
    // the current value of the text field 
    var queryCourseName = this.get('searchCourseName'); 
    this.set('searchResult',App.Exam.find({courseName: queryCourseName}) 

    } 

}); 

이이 App.Exam.find()의 결과를 저장하는 올바른 방법인가를 사용하여 모델을 필터링? 다른 컨트롤러에서 searchResult 속성에 액세스하고 값을 반복하는 방법은 무엇입니까?

답변

0

수행하려는 작업에 따라,하지만 당신은 당신의 ExamController에 재산 searchResult을 설정하면이 일을 :에 needs 지시어를 사용하는 다른 컨트롤러 (들)에, 나중에 수있는 다음

... 
this.set('searchResult', App.Exam.find({courseName: queryCourseName})); 
... 

을 당신의 ExamController에 액세스 :

App.AnotherController = Ember.Controller.extend({ 
    needs: ['exam'], 
    examBinding: 'controllers.exam', 
    ... 
    myFunction: function() { 
    this.get('exam.searchResult') // here are your values 
    } 
}); 

가치가 여기에서 주목할 것은 접미사 examBinding에서 Binding는 MOR를 들어, 두 개의 속성 사이의 바인딩 설정에 타다 알 것입니다 ': [시험', examBinding 'controllers.exam가', '그것은 ANNOT 말한다 전자 정보는 API의 문서의 Ember.Binding

는 내가 요구'에 오류가 솔루션을하려고하면 그것이

+0

도움이되기를 바랍니다 체크 아웃 null의 호출 방법 'lookup' – alexjson

+0

흠, jsfiddle을 설정할 수 있습니까? – intuitivepixel

+0

시험 바인딩 : 'App.ExamController.exam'을 사용할 때 작동합니다. 그러나 searchResult의 값을 accsess하는 방법과 여전히 혼동 스럽습니다. searchResult에서 레코드 1을 원하고 해당 레코드에서 examDate를 가져 오려면 어떻게해야합니까? 지금까지 도움을위한 Thx! – alexjson

관련 문제