AngularJS-4-循環綁定

一、綁定

<html ng-app="lesson" ng-controller="lesson4">

<table>

<thead><th>姓名</th><th>年齡</th><th>星座</th><th>工作年限</th></thead>

<tbody>

<tr ng-repeat="x in UserEntityList">

<td>{{x.Name}}</td><td>{{x.Age}}</td><td>{{x.Constellation}}</td><td>{{x.WorkYear}}</td>

</tr>

</tbody>

</table>

<script src=”scripts/angular-1.1.1.min.js“></script>

<script>

var app = angular.module("lesson",[]);

app.controller("lesson4",function($scope){

$scope.UserEntityList=[

{'Name':'Tom','Age':26,'Constellation':'水瓶座','WorkYear':19},

{'Name':'Jerry','Age':27,'Constellation':''巨蟹座','WorkYear':5},

{'Name':'David','Age':28,'Constellation':''天秤座','WorkYear':6},

{'Name':'Tim','Age':39,'Constellation':''摩羯座','WorkYear':7}

]

})

</script>

二、過濾器

1、排序

正序:<tr ng-repeat="x in UserEntityList | orderBy:'Age'">

倒序:<tr ng-repeat="x in UserEntityList | orderBy:'Age':true">

2、組合排序

正序:<tr ng-repeat="x in UserEntityList | orderBy:['Age','WorkYear']">

倒序:<tr ng-repeat="x in UserEntityList | orderBy:['Age','-WorkYear']">

3、大寫輸出

{{x.Name | uppercase}}

4、序號

<tr ng-repeat="x in UserEntityList">

{{ $index }}

</tr>

5、過濾器

顯示帶39的(模糊查詢):<tr ng-repeat="x in UserEntityList | orderBy:['Age','WorkYear'] | filter:39">

顯示39的(精準查詢):<tr ng-repeat="x in UserEntityList | orderBy:['Age','WorkYear'] | filter:{‘Age’:39}">

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章