我正在尝试从通过jQuery.getJSON
. Ember-data
只要它还不稳定,它就不是一个真正的选择。
App.Project = Ember.Object.extend({
remove: function() {
return $.ajax({
url: '/api/v1/projects/'+this.get('id'),
type: 'DELETE'
});
}
});
App.Project.reopenClass({
findAll: function() {
return jQuery.getJSON('/api/v1/projects').then(
function(response) {
var projects = Ember.A();
if (response.projects !== undefined) {
response.projects.forEach(function (project) {
projects.pushObject(App.Project.create(project));
});
}
return projects;
}
);
}
});
App.ProjectsRoute = Ember.Route.extend({
model: function() {
return App.Project.findAll();
},
events: {
deleteProject: function(project) {
project.remove();
}
}
});
当我按下以下按钮时,它会执行 DELETE API 调用,但它当然不会从数组中删除该项目。我怎样才能从数组中删除该项目?
<button class="btn btn-mini btn-danger" {{action 'deleteProject' this}}><i class="icon-trash"></i> Delete</button>