AngularJS实现购物车功能,表格的删除,查询,排序功能

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>AngularJS实现表格的删除,查询,排序功能</title>
    <script src="angular.js"></script>
    <script type="text/javascript">
        var app = angular.module("myApp",[]);
        app.controller("myCtrl",function ($scope) {
            $scope.shuzu = [{
                id:80,
                name:"iphone",
                price:5400
            },{
                id:150,
                name:"ipad mini",
                price:2200
            },{
                id:120,
                name:"ipad air",
                price:2340
            },{
                id:160,
                name:"ipad",
                price:1420
            },{
                id:130,
                name:"imac",
                price:15400
            }];
            $scope.aflag = "-";
            $scope.aname = "name";
            $scope.paixu = function (clomnName) {
                alert(clomnName);
                $scope.aname = clomnName;
                //判断
                if($scope.aflag == "-"){
                    $scope.aflag = "";
                }else{
                    $scope.aflag = "-"
                }
            };
            $scope.deleteName = function (name) {
                for(index in $scope.shuzu){
                    if($scope.shuzu[index].name == name){
                        $scope.shuzu.splice(index,1);
                    }

                }
            }
            $scope.deleteAll = function () {
                $scope.shuzu = null;
            }
        });

    </script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
    <center>
        <h3>商品列表</h3>
        <input type="text" placeholder="商品名称" ng-model="textName">
        <button ng-click="deleteAll()">删除全部</button><br/><br/>
        <table border="1" cellpadding="10" cellspacing="0">
            <tr>
                <th ng-click="paixu('id')">产品编号</th>
                <th ng-click="paixu('name')">产品名称</th>
                <th ng-click="paixu('price')">产品价格</th>
                <th>功能</th>
            </tr>
            <tr ng-repeat="i in shuzu | filter:textName | orderBy:(aflag+aname)">
                <td>{{i.id}}</td>
                <td>{{i.name}}</td>
                <td>{{i.price}}</td>
                <td><button ng-click="deleteName(i.name)">删除</button></td>
            </tr>
        </table>
    </center>
</body>
</html>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值