商品管理

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>week</title>

    <script src="angular1.4.6.min.js"></script>
    <script>
        var app  = angular.module("myapp",[]);
        app.controller("myctrl",function($scope){
            $scope.goods = [
                {"id":80,"name":"iphone","price":5400,},
                {"id":1200,"name":"ipad mini","price":2200,},
                {"id":500,"name":"ipad air","price":2340,},
                {"id":29,"name":"ipad","price":1420,},
                {"id":910,"name":"imac","price":15400,}
            ];

            $scope.bold = "bold";
            $scope.title = 'name';
            $scope.desc = 0;
            $scope.key = '';

            //删除
            $scope.deletes =function(name){

                var p;
                for( index in     $scope.goods){
                    p = $scope.goods[index];
                    if( p.name == name){
                        $scope.goods.splice(index,1);
                        alert("是否删除"+name+"商品");
                    }

                }

            };
            $scope.delall =function(){
                alert("删除全部");
                $scope.goods.splice($scope.goods);
            };

            //根据标题title排序
            $scope.togg =function(tit){
                $scope.title = tit;
                $scope.desc = !$scope.desc;

            };
        });
    </script>
</head>
<body ng-app="myapp" ng-controller="myctrl">
<center>
    <table cellpadding="10" cellspacing="0" border="1" width="800px">
        <tr>
            <th><input type="text" ng-model="key" placeholder="请输入产品名称关键字"/></th>
            <th colspan="3" align="left" ng-click="delall()">全部删除</th>
        </tr>
        <tr  >
            <th ng-click="togg('id')">产品编号▼</th>
            <th ng-click="togg('name')">产品名称▼</th>
            <th ng-click="togg('price')">产品价格▼</th>
            <th>删除</th>
        </tr>
        <tr ng-repeat="x in goods | filter: {name: key} | orderBy: title : desc">
            <td>{{x.id}}</td>
            <td>{{x.name}}</td>
            <td>{{x.price | currency:"¥"}}</td>
            <td><button ng-click="deletes(x.name)">删除</button></td>
        </tr>
    </table>
</center>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值