Emberjs linkTo helper не загружает модель

У меня есть это приложение Emberjs, которое я создаю в виде корабля, но по какой-то причине, когда я нажимаю linkTo из представления «пациенты», Ember загружает представление «пациент», но не модель. Однако, если я перезагружу страницу по маршруту «/:patient_id», модель загрузится. Что мне не хватает?

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>

person jasongonzales    schedule 20.08.2013    source источник
comment
вы видите какие-либо ошибки в вашей консоли?   -  person intuitivepixel    schedule 21.08.2013
comment
Вот ссылка на скрипку http://jsfiddle.net/jpJ2c/   -  person jasongonzales    schedule 21.08.2013
comment
спасибо за скрипку, но это тот же код, что и в вашем вопросе, и неполное приложение, поэтому будет сложно запустить его и посмотреть, появляются ли какие-либо ошибки в консоли.   -  person intuitivepixel    schedule 21.08.2013


Ответы (2)


Я думаю, это должно сработать. У меня есть только одно маленькое подозрение. Пожалуйста, попробуйте это:

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

Я думаю, что ваш подход может не передать правильный объект помощнику linkTo.

person mavilein    schedule 20.08.2013

Итак, вопрос плохой, мне нужно закрыть его, потому что проблема связана с моделью и ответом, возвращаемым с сервера. Виноват :\

person jasongonzales    schedule 20.08.2013