angularJs利用$scope處理升降序的方法
更新時間:2018年10月08日 11:48:20 作者:泠泠在路上
今天小編就為大家分享一篇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')">點擊數(shù)
<span ng-if="status.click">升序</span>
<span ng-if="!status.click">降序</span>
</td>
<td ng-click="orderBy('title')">標題
<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?Tree?Shaking優(yōu)化機制原理詳解
這篇文章主要為大家介紹了Angular?Tree?Shaking優(yōu)化機制原理詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-10-10
解決ng-repeat產(chǎn)生的ng-model中取不到值的問題
今天小編就為大家分享一篇解決ng-repeat產(chǎn)生的ng-model中取不到值的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-10-10
AngularJS基礎(chǔ) ng-cloak 指令簡單示例
本文主要介紹AngularJS ng-cloak 指令,這里幫大家整理了ng-clock指令的基礎(chǔ)資料,和簡單的代碼實例及效果圖,學(xué)習(xí)AngularJS指令的朋友可以參考下2016-08-08
angularjs學(xué)習(xí)筆記之雙向數(shù)據(jù)綁定
AngularJS在$scope變量中使用臟值檢查來實現(xiàn)了數(shù)據(jù)雙向綁定。和Ember.js數(shù)據(jù)雙向綁定中動態(tài)設(shè)施setter和getter不同,臟治檢查允許AngularJS監(jiān)視那些存在或者不存在的變量。2015-09-09
使用Angular Cli如何創(chuàng)建Angular私有庫詳解
這篇文章主要給大家介紹了關(guān)于使用Angular Cli如何創(chuàng)建Angular私有庫的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-01-01
如何處理Angular?錯誤消息ERROR?Error?NullInjectorError?No?provid
這篇文章主要介紹了如何處理Angular?錯誤消息ERROR?Error?NullInjectorError?No?provider?for?XX2023-07-07
用AngularJS來實現(xiàn)監(jiān)察表單按鈕的禁用效果
本篇文章主要介紹了用AngularJS來實現(xiàn)監(jiān)察表單按鈕的禁用效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下。2016-11-11

