简体   繁体   中英

Emberjs linkTo helper not loading model

I have this Emberjs app I am building looking all ship shape, but for some reason, when I hit the linkTo from the "patients" view Ember loads the "patient" view, but not the model. However, if I reload the page at the "/:patient_id" route, the model loads. What am I missing?

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>

I think this should work. I just have one little suspicion. Plz try this:

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

I think that your approach could maybe not pass the right object to the linkTo helper.

OK, so the question is bad, I need to close it because the issue is with the model and the response coming back from the server. My bad :\\

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM