<!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>
商品管理
最新推荐文章于 2020-12-15 10:06:30 发布