我是angularJs中的新手..我有一个查询如何刷新ng-Repeat中的数据
我的观点看起来像这样:
现在,我按下删除按钮事件,然后记录不从网格删除...
$scope.Deletepovider = function (ProviderListId) {
if (confirm('Are you sure you want to delete this?')) {
var getmsg = AdminService.DeleteProviderDetail(ProviderListId, '/Admin/Delete', $scope.onDeleteCompleted, $scope.onDeleteError);
return true;
} else {
e.stopImmediatePropagation();
e.preventDefault();
return false;
}
}
$scope.onDeleteCompleted = function (response, status) {}
$scope.onDeleteError = function (response, status) {}
答案 0 :(得分:2)
我想说,一般来说,在执行此类操作后,您不希望“刷新”列表。相反,您想要管理它所绑定的列表。考虑这样的事情:
$scope.Deletepovider = function (ProviderListId)
{
if (confirm('Are you sure you want to delete this?'))
{
var getmsg = AdminService.DeleteProviderDetail(
ProviderListId,
'/Admin/Delete',
function () {
// remove the provider from the list the ng-repeat is bound to
// you could use anything like lodash or underscore to find the
// provider by ID (referencing ProviderListId above)
},
function(err) {
});
return true;
}
else
{
e.stopImmediatePropagation();
e.preventDefault();
return false;
}
}
注意:注意我在成功回调中添加的评论。那是你的解决方案。
答案 1 :(得分:1)
是这样,您可以在删除记录后刷新网格。
$scope.delete = function () {
var promiseDeleteStudent = SPACRUDService.delete(ShareData.value);
promiseDeleteStudent.then(function (pl) {
$location.path("/showstudents"); /*write your lists method */
},
function (errorPl) {
$scope.error = 'failure loading Student', errorPl;
});
};
答案 2 :(得分:0)
因此,在检查提供的代码后,您似乎需要稍微更新代码以在成功删除它之后实际更新集合,或者您可以直接从集合中删除记录,然后再转到DeleteProvider
$scope.Deletepovider = function (ProviderListId) {
if (confirm('Are you sure you want to delete this?')) {
var getmsg = AdminService.DeleteProviderDetail(ProviderListId, '/Admin/Delete', $scope.onDeleteCompleted, $scope.onDeleteError);
return true;
} else {
e.stopImmediatePropagation();
e.preventDefault();
return false;
}
}
$scope.onDeleteCompleted = function (response, status) {
$scope.filteredUserRoles = //update the data through service or method
}
$scope.onDeleteError = function (response, status) {}