AngularJS+添加+条件筛选+排序

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>球队</title>
    <script src="../angular-1.5.5/angular.min.js"></script>
    <script>
        var app = angular.module("myapp",[]);
        app.controller("mycont",function ($scope) {
            $scope.users=[{
                    'url':"images/1.png",
                    'name':"Westbrook",
                    'wz':"得分后卫(SG)",
                    "age":24,
                    "qd":"雷霆",
                    "page":1900
                },{
                    'url':"images/2.png",
                    'name':"James",
                    'wz':"大前锋(PF)",
                    "age":23,
                    "qd":"骑士",
                    "page":1900
                },{
                    'url':"images/3.png",
                    'name':"Curry",
                    'wz':"得分后卫(SG)",
                    "age":30,
                    "qd":"勇士",
                    "page":1800
                },{
                    'url':"images/4.png",
                    'name':"Harden",
                    'wz':"小前锋(SG)",
                    "age":13,
                    "qd":"火箭",
                    "page":1800
                },{
                    'url':"images/5.png",
                    'name':"Durant",
                    'wz':"得分后卫(SG)",
                    "age":35,
                    "qd":"勇士",
                    "page":1712
            }];
            $scope.add = function () {
                $scope.users.push({url:"images/5.png",name:$scope.name,wz:$scope.wz,age:$scope.age,qd:$scope.qd,page:0});
                $scope.name = "";
                $scope.wz = "";
                $scope.age = "";
                $scope.qd = "";
            }
            $scope.ageSize = "--请选择--";
            $scope.ageFilter = function (item) {
                if ($scope.ageSize != "--请选择--"){
                    var ageSize = $scope.ageSize;
                    var ageArr = ageSize.split("-");
                    var min = ageArr[0];
                    var max = ageArr[1];
                    var age = item.age;
                    if (age > max || age < min){
                        return false;
                    } else {
                        return true;
                    }
                } else {
                    return true;
                }
            }
            $scope.addpiao = function (item) {
                item.page++;
            }
            /*$scope.revers = false;
             $scope.sortColumn = "name";
             $scope.sort = function (count) {
             if($scope.sortColumn == count){
             $scope.revers=!$scope.revers;
             }
             $scope.sortColumn = count;
             }*/
        })
    </script>
</head>
<body ng-app="myapp" ng-controller="mycont">
    <h1>添加新球员</h1>
    姓名:<input type="text" ng-model="name"><br/>
    位置:<input type="text" ng-model="wz"><br/>
    年龄:<input type="text" ng-model="age"><br/>
    球队:<input type="text" ng-model="qd"><br/>
    <button ng-click="add()">添加新球员</button><br/><br/>
    <h3>用户信息表</h3>
    <input type="text" placeholder="用户名查询" ng-model="search">
    年龄查询 :<select ng-model="ageSize">
        <option>--请选择--</option>
        <option>11-20</option>
        <option>21-30</option>
        <option>31-40</option>
        <option>41-50</option>
    </select ><br/>
    <table cellspacing="0" cellpadding="10" border="soild 1px #000">
        <tr>
            <th>球员</th>
            <th ng-click="sort('name')">姓名</th>
            <th ng-click="sort('wz')">位置</th>
            <th ng-click="sort('age')">年龄</th>
            <th ng-click="sort('qd')">球队</th>
            <th>得票数</th>
            <th>操作</th>
        </tr>
        <tr ng-repeat="item in users|filter:{name:search}|filter:ageFilter"><!--|orderBy:sortColumn:revres-->
            <td><img ng-src="{{item.url}}"></td>
            <td>{{item.name}}</td>
            <td>{{item.wz}}</td>
            <td>{{item.age}}</td>
            <td>{{item.qd}}</td>
            <td>{{item.page}}</td>
            <td><button ng-click="addpiao(item)">投票</button></td>
        </tr>
    </table>
    <p></p>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值