我有这个Emberjs应用程序我正在构建所有船形状,但出于某种原因,当我从“患者”视图点击链接时,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>
答案 0 :(得分:0)
我认为这应该有效。我只有一点怀疑。 Plz试试这个:
{{#each patient in controller.model}}
<td>{{#linkTo 'patient' patient}}{{patient.first_name}}{{/linkTo}}</td>
...
{{/each}}
我认为您的方法可能无法将正确的对象传递给linkTo
帮助程序。
答案 1 :(得分:0)
好的,所以问题很糟糕,我需要关闭它,因为问题在于模型和从服务器返回的响应。我的坏:\