2013-08-20 4 views
2

나는이 Emberjs 앱을 가지고있다. 나는 모든 배 모양을보고있다. 그러나 웬일인지, "patient"뷰에서 linkTo를 눌렀을 때 Ember는 "patient"뷰를로드하지만 모델은로드하지 않는다. . 그러나 "/ : patient_id"경로에서 페이지를 다시로드하면 모델이로드됩니다. 내가 뭘 놓치고 있니?Emberjs linkTo helper not loading model

DS.RESTAdapter.map 'App.InboxRecording', 
    recording: {embedded: 'always'} 

App.Store = DS.Store.extend 
    adapter: DS.RESTAdapter.create()  

App.Router.map()-> 
    this.resource(
    'patients', {path: '/' }, -> 
    this.resource(
     'patient', {path: '/:patient_id' } 
    ) 
) 
App.PatientsRoute = Ember.Route.extend({ 
    model:() -> 
    App.Patient.find() 
}); 

App.PatientRoute = Ember.Route.extend({ 
    model: (params) -> 
    App.Patient.find(params.patient_id) 
}); 

App.Patient = DS.Model.extend({ 
    first_name: DS.attr('string'), 
    last_name: DS.attr('string'), 
    last_ecg_taken: DS.attr('date'), 
    date_of_birth: DS.attr('date'), 
    email: DS.attr('string'), 
    gender: DS.attr('string'), 
    height: DS.attr('string'), 
    weight: DS.attr('string'), 
    medications: DS.attr('string'), 
    smoker: DS.attr('string'), 
    inbox_recordings: DS.hasMany('App.InboxRecording') 
    //medical_conditions: DS.attr('string'), 
}); 

App.InboxRecording = DS.Model.extend({ 
    flagged: DS.attr('boolean'), 
    read: DS.attr('boolean'), 
    overread: DS.attr('boolean'), 
    patient: DS.belongsTo('App.Patient'), 
    recording: DS.belongsTo('App.Recording') 
    //filter: DS.hasMany('App.Filter') 
}); 

App.Recording = DS.Model.extend({ 
    activities: DS.attr('string'), 
    avg_heart_rate: DS.attr('string'), 
    recorded_at: DS.attr('date'), 
    symptoms: DS.attr('string'), 
    inbox_recording: DS.belongsTo('App.InboxRecording') 
}); 



<script type="text/x-handlebars" data-template-name="application"> 
{{outlet}} 
</script> 

<script type="text/x-handlebars" data-template-name="patients"> 
    <div class="container"> 
    <div class="row"> 

     <div class="span8"> 
     <div id="patient-lookup" class="panel"> 
      <h2>Patient Lookup</h2> 
      <label for="lookup">Last Name</label> 
      <input id="lookup" name="lookup" placeholder="Enter patient's last name"/> 
      <button class="btn btn-primary">Search</button> 
     </div> 
     <table class="table"> 
      <thead> 
      <tr> 
       <th>First Name</th> 
       <th>Last Name</th> 
       <th>Last ECG Taken</th> 
       <th>DOB</th> 
      </tr> 
      </thead> 
      <tbody> 
      {{#each controller}} 
      <tr> 
       <td>{{#linkTo 'patient' this}}{{first_name}}{{/linkTo}}</td> 
       <td>{{last_name}}</td> 
       <td>{{last_recording_taken }}</td> 
       <td>{{date_of_birth }}</td> 
      </tr> 
      {{/each}} 
      </tbody> 
     </table> 
     </div> 

    </div> 
    </div> 
</script> 

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

<script type="text/x-handlebars" data-template-name="patient"> 
<div class="link"> 
{{#linkTo 'patients'}}Back to all patients{{/linkTo}} 
</div> 

<h1>Email: {{email}}</h1> 
{{#if inbox_recordings.length}} 
    <div class="container"> 
    <table class="table"> 
     <thead> 
     <tr> 
      <th>Flagged</th> 
      <th>Date & Time</th> 
      <th>Symptoms</th> 
      <th>Activities</th> 
      <th>BPM</th> 
      <th>View PDFS</th> 

     </tr> 
     </thead> 
     <tbody> 
     {{#each inbox_recording in inbox_recordings}} 
     <tr {{bindAttr class="inbox_recording.read:isRead"}}> 
      <td {{bindAttr class="inbox_recording.flagged:isFlagged"}}>{{view Ember.Checkbox checkedBinding="inbox_recording.flagged" class="toggle"}}</td> 
      {{#with inbox_recording.recording}} 
      <td>{{recorded_at}}</td> 
      <td>{{symptoms}}</td> 
      <td>{{activities}}</td> 
      <td>{{avg_heart_rate}}</td> 
      {{/with}} 
      <td> 
      {{#each filter in recording.filter }} 
       <a {{action 'markAsRead' filter}}{{bindAttr href="filter.link"}}>{{filter.name}}</a> 
      {{/each}} 
      </td> 
      <td>{{inbox_recording.overread}}</td> 
     </tr> 
     {{/each}} 
     </tbody> 
    </table> 
    </div> 
{{/if}} 
</script> 
+0

콘솔에 오류가 있습니까? – intuitivepixel

+0

다음은 바이올린 toohttp에 대한 링크입니다 : //jsfiddle.net/jpJ2c/ – jasongonzales

+0

바이올린에 감사드립니다.하지만 질문과 앱의 코드가 같아서 실행하기가 어렵습니다. 콘솔에 오류가 나타나면 – intuitivepixel

답변

0

OK, 문제는 모델과 응답이 서버에서 돌아 오는 문제이므로 닫아야합니다. 내 잘못 : \

0

나는 이것이 효과가 있다고 생각한다. 나는 다만 작은 의혹이있다. Plz은 이것을 시도 :

{{#each patient in controller.model}} 
    <td>{{#linkTo 'patient' patient}}{{patient.first_name}}{{/linkTo}}</td> 
    ... 
{{/each}} 

내가 당신의 접근 방식은 어쩌면 linkTo 도우미에 대한 권리 개체를 전달할 수 없다고 생각합니다.

+0

흠 .... 그게 작동하지 않는 것 같습니다. 그래도 많은 감사합니다. – jasongonzales