angular(过滤器)查询,删除

<!DOCTYPE html>
<html>
 <head>
  <meta charset="UTF-8">
  <title></title>
  <script type="text/javascript" src="js/angular.min.js" ></script>
  <script type="text/javascript">
   var app = angular.module("myApp",[]);
   app.controller("myCtrl",function($scope){
    //准备数据源
    $scope.goods = [
      {"name":"冰激凌","price":3,"brand":"蒙牛"},
      {"name":"老冰棍","price":1,"brand":"老北京"},
      {"name":"西瓜","price":10,"brand":"麒麟"},
      {"name":"可乐","price":5,"brand":"百事"}];
    //过滤条件
    $scope.searchKey;
    //排序条件
    $scope.orderByKey;
    //删除
    $scope.deletGoods = function(i){
     $scope.goods.splice(i,1);//通过索引删除一条
    }
   });
  </script>
  
 </head>
 <body ng-app="myApp" ng-controller="myCtrl">
  <center>
   查询:<input type="text" ng-model="searchKey" />&nbsp;&nbsp;
   排序条件:<select ng-model="orderByKey">
    <option value="">--请选择--</option>
    <option value="name">--按名字正序--</option>
    <option value="-name">--按名字倒序--</option>
    <option value="price">--按价钱正序--</option>
    <option value="-price">--按价钱倒序--</option>
   </select>
   <br />
   <table width="400px" border="1px" bordercolor="red" cellpadding="1px" cellspacing="1px" >
    <tr style="background-color: grey;">
     <td><input type="checkbox"/></td>
     <td>序号</td>
     <td>名字</td>
     <td>价格</td>
     <td>品牌</td>
     <td>操作</td>
    </tr>
    <tr ng-repeat="g in goods |filter:searchKey | orderBy:orderByKey">
     <td><input type="checkbox"/></td>
     <td>{{$index+1}}</td>
     <td>{{g.name}}</td>
     <td>{{g.price}}</td>
     <td>{{g.brand}}</td>
     <td><input type="button" value="删除" ng-click="deletGoods($index);"/></td>
    </tr>
   </table>
   
  </center>
 </body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值