模型没有'在Emberjs中删除记录后不会更新
Model doesn't update after record delete in Emberjs
实际上,我在Ember应用程序中使用Ajax而不是Ember Data来执行CRUD操作。
场景是每当我删除记录时,模型都不会更新。我有一个项目列表,每个项目前面都有一个"删除"按钮
以下是与删除相关的操作:
deleteItem: function(item){ //function for delete action
var id = item.get('id');
$.ajax({
type : "POST",
url : "http://pioneerdev.us/users/deleteProject/" + id,
dataType : "json",
success : function(data) {
console.log('success');
}
});
alertify.success('Record Deleted!');
window.setTimeout(function(){location.reload()},3000)
}
如您所见,我正在使用location.reload
手动重新加载模型。如果有人感兴趣,他可以在我的GitHub回购上查看完整的来源
有更好的方法吗?
我用一些注释更新了您的代码。我希望它能有所帮助。
actions: {
deleteItem: function(item){
var id = item.get('id');
var controller = this;
$.ajax({
type : "POST",
url : "http://pioneerdev.us/users/deleteProject/" + id,
dataType : "json",
// use the success callback to safe notify the user when the record is deleted
// in your current implementation the alert is displayed even if an error occurs in the server.
success : function(data) {
// no need to location.reload, the removeObject will remove that item
controller.removeObject(item);
alertify.success('Record Deleted!');
}
});
}
},
filteredContent : function() {
var searchText = this.get('searchText'), regex = new RegExp(searchText, 'i');
return this.get('arrangedContent').filter(function(item) {
return regex.test(item.projectname);
});
// instead of model use model.length so your template will update when some item is added or removed
}.property('searchText', 'model.length')
相关文章:
- 使用Rails 3中的AJAX删除记录
- 使用jquery和ajax删除记录
- Rails Production-可以工作,但不能编辑/删除/创建记录
- 尝试使用Promises删除记录
- 如果用户选择离开网页,如何删除记录
- 通过javascript从浏览器历史记录中删除URL
- 如何在删除第二个表中的所有记录后删除具有日期值的tr
- 无需点击php即可确认记录删除
- 删除记录确认消息
- 模型没有'在Emberjs中删除记录后不会更新
- 如何在js中从数组中删除记录
- Delete方法不适用于Indexed DB HTML5.它返回成功,但未删除记录
- 立即删除范围记录 - mongodb
- 剑道网格在删除后仍显示最后一条记录
- 从外部 iFrame 重定向和链接中删除历史记录
- 从 ExtJs 4.1 存储中删除记录时触发哪些事件
- 本地存储循环删除 2 条记录后缺少记录(在不同的页面上)
- 如何在 mvc3 Web 应用程序的生产版本中删除 JS 日志记录调用
- 为什么使用挖空在确认框中单击“取消”时删除记录
- Postgre使用Ajax函数在带有复选框的数据库中进行多记录删除查询,不会返回任何结果;不起作用