AngularJS+日程表+显示、隐藏 +orderBy排序

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>日程表</title>
    <script src="../angular-1.5.5/angular.min.js"></script>
    <script>
        var data = {
            user:"李四",
            items:[
                {action:"约刘诗诗吃饭",done:false},
                {action:"约刘诗诗跳舞",done:false},
                {action:"约刘诗诗敲代码",done:true},
                {action:"约刘诗诗爬长城",done:false},
                {action:"约刘诗诗逛天坛",done:false},
                {action:"约刘诗诗看电影",done:false}
            ]
        };
        var app = angular.module("myapp",[]);
        app.filter("todo",function () {
            return function (a,flag) {
                var arr = [];
                for (var i=0;i<a.length;i++){
                    if (a[i].done == false){
                        arr.push(a[i]);
                    } else {
                        if (flag == true){
                            arr.push(a[i]);
                        }
                    }
                }
                return arr;
            }
        })
        app.controller("mycont",function ($scope) {
            $scope.data = data;
            $scope.count = function () {
                var n = 0;
                for (var i=0;i<data.items.length;i++){
                    if (data.items[i].done == false){
                        n++;
                    }
                }
                return n;
            }
            $scope.add = function () {
                $scope.data.items.push({action:$scope.additem,done:false});
            }
        })
    </script>
</head>
<body ng-app="myapp" ng-controller="mycont">
<h2>{{data.user}}的日程<span>{{count}}</span></h2>
 <input type="text" ng-model="additem">
  <button ng-click="add()">添加</button>
 <table border="soild 1px #000" cellpadding="10" cellspacing="0">
     <thead>
     <tr>
         <th>序号</th>
         <th>日程</th>
         <th>完成</th>
     </tr>
     </thead>
     <tbody>
     <tr ng-repeat="item in data.items|todo:complate">
         <td>{{$index}}</td>
         <td>{{item.action}}</td>
         <td><input type="checkbox" ng-model="item.done"></td>
     </tr>
     </tbody>
 </table>
 <div>显示全部<input type="checkbox" ng-model="complate"></div>
</body>
</html>


orderBy排序
<!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.arr = ["1","2","3","4"];
            $scope.data = [{
                "name":"zs",
                "age":"20",
                "sex":"boy",
                "salary":"15000"
            },{
                "name":"ls",
                "age":"22",
                "sex":"boy",
                "salary":"13000"
            },{
                "name":"ww",
                "age":"18",
                "sex":"girl",
                "salary":"12000"
            }];
            $scope.ins="";
            $scope.revers = false;
            $scope.sortColumn = "name";
            $scope.sort = function (count) {
                if($scope.sortColumn == count){
                    $scope.revers=!$scope.revers;
                }
                $scope.sortColumn = count;
            }
        })
        app.filter("word",function () {
            return function (msg,flag) {
                return msg.replace(/枪|法功/g,flag);
            }
        })
        app.filter("word2",function () {
            return function (msg,flag) {
                return msg.replace(/枪|法功/g,function () {
                    var contant = "";
                    for (var i = 0; i < word.length; i++){
                        contant+="*";
                    }
                    return contant;
                });
            }
        })
    </script>
</head>
<body ng-app="myapp" ng-controller="mycont">
	//自定义过滤器
    <p>{{1000|currency:"¥"}}</p>
    <p>{{"Hello"|uppercase}}</p>
    <p>{{"Hello"|lowercase}}</p>
    <p>{{1507774056568|date:"yyyy-MM-dd hh-ss-mm EEE"}}</p>
    <ul>
        <li ng-repeat="item in arr|limitTo:2">{{item}}</li>
    </ul>
    <input type="text" ng-model="search">
    <table cellpadding="10" cellspacing="0" border="solid 1px #000" >
        <thead>
        <tr>
            <th ng-click="sort('name')">姓名</th>
            <th ng-click="sort('age')">年龄</th>
            <th ng-click="sort('sex')">性别</th>
            <th ng-click="sort('salary')">薪资</th>
        </tr>
        </thead>
        <tbody>
        <tr ng-repeat="item in data|filter:{name:search}|orderBy:sortColumn:revres">
            <td>{{item.name}}</td>
            <td>{{item.age}}</td>
            <td>{{item.sex}}</td>
            <td>{{item.salary}}</td>
        </tr>
        </tbody>
    </table>
    <input type="text" ng-model="ins">
    <p>{{ins|word:'#'}}</p>
    <p>{{ins|word2}}</p>
</body>
</html>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
循环比赛日程表是一种常见的算法问题,可以使用递归或迭代的方式来生成日程表。下面是一个使用C++编写的循环比赛日程表的示例代码: ```cpp #include <iostream> #include <vector> using namespace std; void generateSchedule(int teams) { if (teams % 2 != 0) { teams++; // 如果队伍数为奇数,添加一个虚拟队伍 } int rounds = teams - 1; // 总轮次数 int matches = teams / 2; // 每轮的比赛场次 vector<vector<int>> schedule(rounds, vector<int>(matches)); // 初始化第一轮的比赛安排 for (int i = 0; i < matches; i++) { schedule[0][i] = i + 1; } // 生成后续轮次的比赛安排 for (int round = 1; round < rounds; round++) { for (int match = 0; match < matches; match++) { int team1 = schedule[round - 1][match]; int team2; // 计算每个队伍的对手 if (match == 0) { team2 = teams - 1; } else { team2 = schedule[round - 1][match - 1]; } // 考虑虚拟队伍的情况 if (team1 == teams - 1 || team2 == teams - 1) { team1 = (team1 + 1) % (teams - 1); team2 = (team2 + 1) % (teams - 1); } schedule[round][match] = team2; } } // 打印比赛日程表 for (int round = 0; round < rounds; round++) { cout << "Round " << round + 1 << ": "; for (int match = 0; match < matches; match++) { cout << schedule[round][match] << " vs " << teams - schedule[round][match] - 1 << " "; } cout << endl; } } int main() { int teams; cout << "Enter the number of teams: "; cin >> teams; generateSchedule(teams); return 0; } ``` 这段代码中,我们首先根据输入的队伍数计算总轮次数和每轮的比赛场次。然后,使用一个二维向量 `schedule` 来存储比赛安排。我们从第一轮开始,逐轮生成比赛对阵,并将结果存储在 `schedule` 中。最后,打印出比赛日程表。 希望这个示例代码对你有帮助!

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值