AngularJS的RESTful Web服务 - 从表中删除一行AngularJS、RESTful、Web

由网友(一路上有你.)分享简介:我需要从我的表中删除一行,但我不想为了看到更新的行重新加载或刷新我所有的表。I need to delete a row from my table but I don't want to reload or refresh all my table in order to see the updated rows....

我需要从我的表中删除一行,但我不想为了看到更新的行重新加载或刷新我所有的表。

I need to delete a row from my table but I don't want to reload or refresh all my table in order to see the updated rows.

var demoApp = angular.module("demoApp", ["ngResource"]);

// Controller
demoApp.controller("categoryController", function($scope,   deleteCategorieService, categoriesService){
    $scope.categories = categoriesService.query();

    $scope.deleteCategory = function(id){
        deleteCategoryService.deleteCategory({id: id});
        // I want to avoid this method to refresh my table.
        // $scope.categories = categoriesService.query();
    }; 
 });

// Factories
demoApp.factory("deleteCategorieService", function($resource){
    return $resource("/demopro/deleteCategory/:id", {}, {
        deleteCategory: {
            method: "DELETE",
            params: {id: "@id"}
        }
    });
});

demoApp.factory("categoriesService", function($resource){
    return $resource("/demopro/categories", {}, {
        listAllCategories : {
           method: "GET",
           isArray: true
        }
    });
});

我怎么能这样做?

How can I do that?

推荐答案

如果问题是,你想避免刷新列表时发生在闪烁,只是在更新成功的回调列表中。是这样的:

If the problem is that you want to avoid the flickering that happens when refreshing the list, just update the list in the success callback. Something like:

$scope.deleteCategory = function(id){
    deleteCategoryService.deleteCategory({id: id},
        function(success) {
            $scope.categories = categoriesService.query();
        });
};
阅读全文

相关推荐

最新文章