我正在使用Ember CLI学习EmberJS,但我在模板中显示夹具模型时遇到问题
router.js:
Router.map(function() {
this.resource('calendars', {path: '/'}, function () {
this.route('new');
});
});
模板/ calendars.hbs
<div class="col-md-4">
<ul class="list-group">
{{#each calendar in model}}
<li>{{calendar.name}}</li>
{{/end}}
</ul>
</div>
路由/ calendars.js
import Ember from 'ember';
export default Ember.Route.extend({
model: function () {
return this.store.find('calendar');
}
});
模型/ calendar.js
import DS from 'ember-data';
var Calendar = DS.Model.extend({
name: DS.attr('string')
});
Calendar.reopenClass({
FIXTURES: [
{id: 1, name: 'myCalendar'},
{id: 2, name: 'mySecondCalendar'}
]
});
export default Calendar;
适配器/ application.js中
import DS from "ember-data";
export default DS.FixtureAdapter.extend({});
但是,当我访问根URL /时,服务器崩溃时出现以下错误消息
File: nodecal/templates/calendars.hbs
Cannot read property 'description' of undefined
知道为什么会这样吗?
答案 0 :(得分:4)
Your closing tag in your template is incorrect。将其更改为:
{{#each calendar in model}}
<li>{{calendar.name}}</li>
{{/each}}