AngularJS的RESTful Web服务 - 从表中删除一行 [英] AngularJS RESTful Web Service - Delete row from table

查看:154
本文介绍了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.

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();
        });
};

这篇关于AngularJS的RESTful Web服务 - 从表中删除一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆