todo is not defined
当我尝试destoryRecord
在商店中的某件商品上调用该方法时,我目前正在接收。我试图用多种方式重写这段代码,但我似乎仍然遇到了问题。
这是我正在使用的文件。它可以很好地发布记录,但我只是在删除它们时遇到问题。
// todo/controller.js
import Ember from 'ember';
export default Ember.Controller.extend({
actions: {
createTodo: function() {
this.store.createRecord('todo', {
name: this.get('name'),
createdAt: new Date()
});
this.set('name', '');
},
removeTodo: function() {
this.store.find('todo', todo).then(function(todo) {
todo.destroyRecord();
});
}
}
});
// todo/model.js
import DS from 'ember-data';
export default DS.Model.extend({
name: DS.attr('string'),
createdAt: DS.attr('date')
});
// todo/route.js
import Ember from 'ember';
export default Ember.Route.extend({
model: function() {
return this.store.findAll('todo');
}
});
// todo/template.hbs
{{outlet}}
<div class="jumbotron">
<h2 class="text-center">Add a Todo!</h2>
</div>
<div class="row">
<div class="col-sm-10 col-sm-offset-1">
<div class="panel panel-default">
<div class="panel-heading">
<label for="Todo">Add a Todo!</label>
{{input value=name placeholder="Add a Todo"}}
<button class="btn btn-default" {{action "createTodo"}}>Publish</button>
</div>
{{#each model as |todo|}}
<div class="panel-body">
<ul>
<li>
<button class="btn btn-default" {{action "removeTodo"}}>x</button>
{{todo.name}}</li>
</ul>
</div>
{{/each}}
</div>
</div>
</div>