angularjs表格批量删除和全选反选

本文介绍了一个使用AngularJS实现的商品管理系统示例,该系统包括商品列表显示、排序、过滤、单选及全选功能,并提供了批量删除等功能。通过这个示例可以了解AngularJS的数据绑定和指令等基本用法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


<style>
    table {
        border: 1px solid #000;
        border-collapse: collapse;
    }

    tr, td {
        border: 1px solid #000;
        border-collapse: collapse;
        padding: 10px;
    }
    .font{
        color: red;
    }
</style>
<script src="script/angular.min.js"></script>
<script>
    var myapp = angular.module("myapp", []);
    var items = [
        {"nums": "1234", "name": "ipad", "price": 3400, "kucun": 10,check:false},
        {"nums": "1547", "name": "iphone8", "price": 8900, "kucun": 100,check:false},
        {"nums": "1456", "name": "iphone9", "price": 10800, "kucun": 520,check:false},
        {"nums": "1454", "name": "ipad5", "price": 5600, "kucun": 40,check:false}
    ];
    myapp.controller("myctrl", function ($scope) {
        $scope.items = items;
        $scope.delete = function ($index) {

            if($index>=0){
                if(confirm("是否删除"+$scope.items[$index].name+"商品") ){
                    $scope.items.splice($index,1);
                }
            }
        };
        $scope.order="nums";
        $scope.allcheck=false;
        $scope.ischeck=false;
        $scope.checkall=function () {
            if($scope.allcheck=true){
                for(var i=0;i<$scope.items.length;i++){
                    $scope.items[i].check=true;
                }
            }else {
                for(var i=0;i<$scope.items.length;i++){
                    $scope.items[i].check=false;
                }
            }
        }
        $scope.itemcheck=function () {
            var flag=0;
            for(var i=0;i<$scope.items.length;i++){
                if($scope.items[i].check==true){
                    flag++;
                }
            }
            if(flag==$scope.items.length){
                $scope.allcheck=true;
            }else {
                $scope.allcheck=false;
            }
        }
        $scope.deleteall=function () {
            var is=confirm("是否删除");
            if(is==true){
                var arr=[];
                for(var i=0;i<items.length;i++){
                    if(items[i].check==false){
                        arr.push(items[i]);
                    }
                }
                $scope.items=arr;
            }
        };
        $scope.addclass=function (name) {

                return "font";

        }

    });
</script>
<body ng-app="myapp" ng-controller="myctrl">
<input type="text" ng-model="query"/>
<button ng-click="deleteall()">批量删除</button>
<table>
    <tr>
        <td><input type="checkbox" ng-model="allcheck" ng-click="checkall()"/></td>
        <td ng-click="haha1('nums'); desc=!desc" ng-class="addclass('nums')">id</td>
        <td ng-click="haha1('name'); desc=!desc" ng-class="addclass('nums')">名称</td>
        <td ng-click="haha1('price'); desc=!desc" ng-class="addclass('nums')">价格</td>
        <td ng-click="haha1('kucun'); desc=!desc" ng-class="addclass('nums')">库存</td>
        <td>操作</td>
    </tr>
    <tr ng-repeat="item in items | orderBy:order:desc | filter:query">
        <td><input type="checkbox"ng-model="item.check" ng-click="itemcheck()"/></td>
        <td>{{item.nums}}</td>
        <td>{{item.name}}</td>
        <td>{{item.price | currency:'¥:'}}</td>
        <td>{{item.kucun}}</td>
        <td>
            <button ng-click="delete($index)">删除</button>
        </td>
    </tr>
</table>
</body>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值