2013-08-20 94 views
2

我有這個Emberjs應用我建立期待所有船的形狀,但由於某些原因,當我從「病人」打linkTo查看灰燼裝入「病人」的觀點,但不是模型。但是,如果我在「/:patient_id」路徑上重新加載頁面,則模型會加載。我錯過了什麼?Emberjs linkTo助手不加載模型

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