菜鸡学AngularJS 04 循环绑定、排序、搜索

1:循环绑定数组

PS:ng-repeat = "i in 数组名" ,i为数组每次循环出来的结果
<!doctype html>
<html ng-app = "myapp" ng-controller = "TestController">
<head>
    <script src="http://code.angularjs.org/angular-1.0.1.min.js"></script>
</head>
<body>
    <ul ng-repeat = "i in Arr">
        <li>{{i}}</li>
    </ul>
</body>
<script>
    var app = angular.module('myapp', []);
    app.controller('TestController', function($scope) {
        $scope.Arr = ['arr1','arr2','arr3'];
    });
</script>
</html>

2:表格循环绑定二维数组

PS:{{循环步增名[下标]}}
<!doctype html>
<html ng-app = "myapp" ng-controller = "TestController">
<head>
    <script src="http://code.angularjs.org/angular-1.0.1.min.js"></script>
</head>
<body>
    <table>
        <thead>
            <tr>
                <th>name:</th>
                <th>age:</th>
            </tr>
        </thead>
        <tbody>
            <tr ng-repeat = "a in ArrT">
                <td>{{a[0]}}</td>
                <td>{{a[1]}}</td>
            </tr>
        </tbody>
    </table>
</body>
<script>
    var app = angular.module('myapp', []);
    app.controller('TestController', function($scope) {
        $scope.ArrT = [
            ['jack',15],
            ['Tom',20],
        ];
    });
</script>
</html>

3:循环绑定对象数组,并且对其进行排序和搜索

PS:{{步增名.对象键名}}
PS: orderBy:['排序对象键名','-排序对象键名'] 可以排序多个条件,如果要倒叙就以 - 开头。
PS: filter:{ } 搜索关键字,可以数字、字符串、对象键值。
PS:$index 这个是自动生成ID的关键以0开始。
<!doctype html>
<html ng-app = "myapp" ng-controller = "TestController">
<head>
    <script src="http://code.angularjs.org/angular-1.0.1.min.js"></script>
</head>
<body>
    <table>
        <thead>
            <tr>
                <th>ID</th>
                <th>name:</th>
                <th>age:</th>
                <th>work</th>
            </tr>
        </thead>
        <tbody>
            <tr ng-repeat = "o in ArrObj | orderBy:['age','-work'] | filter:22 | filter:{Name:Tc} ">
                <td>{{$index + 1}}</td>
                <td>{{o.Name}}</td>
                <td>{{o.Age}}</td>
                <td>{{o.work}}</td>
            </tr>
        </tbody>
    </table>
</body>
<script>
    var app = angular.module('myapp', []);
    app.controller('TestController', function($scope) {
        $scope.ArrObj = [
            {Name:'jerry',Age:22,work:4},
            {Name:'Toonz',Age:13,work:2},
            {Name:'Tc',Age:22,work:3},
        ];
    });
</script>
</html>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容