angularJs利用$scope處理升降序的方法
如下所示:
<div ng-app="module" ng-controller="ctrl">
<table border="1" width="600">
<tr>
<td ng-click="orderBy('id')">編號
<span ng-if="status.id">升序</span>
<span ng-if="!status.id">降序</span>
</td>
<td ng-click="orderBy('click')">點(diǎn)擊數(shù)
<span ng-if="status.click">升序</span>
<span ng-if="!status.click">降序</span>
</td>
<td ng-click="orderBy('title')">標(biāo)題
<span ng-if="status.title">升序</span>
<span ng-if="!status.title">降序</span>
</td>
</tr>
<tr ng-repeat="(k,v) in data">
<td>{{v.id}}</td>
<td>{{v.click}}</td>
<td>{{v.title}}</td>
</tr>
</table>
</div>
<script>
var m = angular.module('module', []);
m.controller('ctrl', ['$scope', '$filter', function ($scope, $filter) {
$scope.data = [
{id: 1, click: 100, title: '百度'},
{id: 2, click: 200, title: '谷歌'},
{id: 3, click: 300, title: '騰訊'},
];
//記錄排序的狀態(tài)
$scope.status = {id: false, click: false, title: false};
$scope.orderBy = function (field) {
/*切換升序和降序*/
$scope.status[field]=!$scope.status[field];
$scope.data = $filter('orderBy')($scope.data, field, $scope.status[field]);
}
}]);
</script>
效果圖:

以上這篇angularJs利用$scope處理升降序的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Angular.js項(xiàng)目中使用gulp實(shí)現(xiàn)自動化構(gòu)建以及壓縮打包詳解
基于流的前端自動化構(gòu)建工具,利用gulp可以提高前端開發(fā)效率,特別是在前后端分離的項(xiàng)目中。下面這篇文章主要給大家介紹了關(guān)于在Angular.js項(xiàng)目中使用gulp實(shí)現(xiàn)自動化構(gòu)建以及壓縮打包的相關(guān)資料,需要的朋友可以參考下。2017-07-07
angularjs自定義ng-model標(biāo)簽的屬性
這篇文章主要介紹了angularjs自定義ng-model標(biāo)簽的屬性的相關(guān)資料,需要的朋友可以參考下2016-01-01
Angularjs中的驗(yàn)證input輸入框只能輸入數(shù)字和小數(shù)點(diǎn)的寫法(推薦)
這篇文章主要介紹了Angularjs中的驗(yàn)證input輸入框只能輸入數(shù)字和小數(shù)點(diǎn)的寫法,需要的朋友可以參考下2017-08-08
AngularJS入門教程之?dāng)?shù)據(jù)綁定用法示例
這篇文章主要介紹了AngularJS之?dāng)?shù)據(jù)綁定用法,結(jié)合實(shí)例形式分析了AngularJS基于內(nèi)置指令ng-model實(shí)現(xiàn)數(shù)據(jù)綁定的操作技巧,需要的朋友可以參考下2016-11-11
解決angularjs service中依賴注入$scope報錯的問題
今天小編就為大家分享一篇解決angularjs service中依賴注入$scope報錯的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-10-10
AngularJS中如何使用$http對MongoLab數(shù)據(jù)表進(jìn)行增刪改查
這篇文章主要介紹了AngularJS中如何使用$http對MongoLab數(shù)據(jù)表進(jìn)行增刪改查的相關(guān)資料,需要的朋友可以參考下2016-01-01
利用VS Code開發(fā)你的第一個AngularJS 2應(yīng)用程序
這篇文章主要給大家介紹了關(guān)于利用VS Code如何開發(fā)你的第一個AngularJS 2應(yīng)用程序的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友下面來一起看看吧。2017-12-12

