AngularJs实现添加排序

AngularJs实现添加查询排序

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        table{
            border-collapse: collapse;
        }
        tr,td{
            border: 1px solid #000 ;
        }
        .bt{
            background: #0a9dc7;
        }
    </style>
    <script src="angular-1.5.5/angular.min.js"></script>
    <script>
        var myapp=angular.module("myapp",[]);
        myapp.controller("myCtrl",function ($scope) {
            $scope.data=[{
                name:"张三",
                wz:"控球后卫",
                num:"11",
                ps:"999"
            },{
                name:"李四",
                wz:"大前锋",
                num:"21",
                ps:"888"
            },{
                name:"王五",
                wz:"小前锋",
                num:"23",
                ps:"777"
            },{
                name:"赵六",
                wz:"中锋",
                num:"10",
                ps:"666"
            },{
                name:"周七",
                wz:"得分后卫",
                num:"1",
                ps:"555"
            }];
            $scope.search="";
            $scope.search2="";
            $scope.$watch("search",function (value) {
                console.log(value);
                if(value.indexOf("枪")!=-1){
                    alert("包含敏感字");
                    $scope.search="";
                }else {
                    $scope.search2=$scope.search;
                }
        });
            $scope.sort="--请选择--";
            $scope.fun=function () {
                if($scope.sort!="--请选择--")
                {
                    if($scope.sort=="--票数倒序--"){
                       $scope.revers=true;
                    }else if($scope.sort=="--票数正序--"){
                        $scope.revers=false;
                    }
                }
            };
            $scope.show=false;
            $scope.add=function () {
                $scope.show=true;
            };
            $scope.push=function () {
                for(var i=0;i<$scope.data.length;i++){
                    if($scope.name==$scope.data[i].name){
                        alert("重复");
                        return;
                    }
                    if($scope.name==null||$scope.wz==null){
                        alert("为空");
                        return;
                    }
                }
           $scope.data.push({name:$scope.name,wz:$scope.wz,num:$scope.num,ps:$scope.ps})
            }
        })
        
    </script>
</head>
<body ng-app="myapp" ng-controller="myCtrl">
<span>查询</span>
<input type="text" ng-model="search">
<span>排序</span>
<select ng-model="sort" ng-change="fun()">
    <option>--请选择--</option>
    <option>--票数倒序--</option>
    <option>--票数正序--</option>
</select><br>
<button ng-click="add()" class="bt">新增球员</button>
<table>
    <thead>
    <tr>
        <td>姓名</td>
        <td>位置</td>
        <td>球号</td>
        <td>票数</td>
    </tr>
    </thead>
    <tbody>
     <tr ng-repeat="item in data |filter:search2|orderBy:'ps':revers">
         <td>{{item.name}}</td>
         <td>{{item.wz}}</td>
         <td>{{item.num}}</td>
         <td>{{item.ps}}</td>
     </tr>
    </tbody>
</table>
<table ng-show="show">
    <tr>
        <td>姓名</td>
        <td><input type="text" ng-model="name"></td>
    </tr>
    <tr>
        <td>位置</td>
        <td><input type="text" ng-model="wz"></td>
    </tr>
    <tr>
        <td>球号</td>
        <td><input type="text" ng-model="num"></td>
    </tr>
    <tr>
        <td>票数</td>
        <td><input type="text" ng-model="ps"></td>
    </tr>
    <tr>
        <td colspan="2"><button ng-click="push()">添加</button></td>
    </tr>
</table>
</body>
</html>


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值