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>
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。