首頁 > web前端 > js教程 > 主體

使用Angular如何實現三角箭頭標註功能

亚连
發布: 2018-06-14 16:45:21
原創
1798 人瀏覽過

這篇文章主要介紹了Angular實現的自訂模糊查詢、排序及三角箭頭標註功能,涉及AngularJS針對頁面table元素的遍歷、查詢、判斷、排序等相關操作技巧,需要的朋友可以參考下

本文實例講述了Angular實現的自訂模糊查詢、排序及三角箭頭標註功能。分享給大家供大家參考,具體如下:

先來看看運行效果:

具體程式碼如下:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>www.jb51.net Angular模糊查询、排序</title>
  <style>
    *{
      margin: 0;
      padding: 0;
    }
    table{
      border-collapse: collapse;
    }
    td{
      padding: 10px;
      border: 1px solid #000;
    }
    .top{
      display: inline-block;
      width: 0;
      height: 0;
      border: 10px solid transparent;
      border-top:10px solid red;
    }
    .bot{
      display: inline-block;
      width: 0;
      height: 0;
      border: 10px solid transparent;
      border-bottom:10px solid red;
    }
  </style>
  <script src="angular.min.js"></script>
  <script>
    var myapp=angular.module("myapp",[]);
    myapp.controller("myCtrl",function ($scope) {
      var userInfo=[
        {name:"marry",salary:12345,sex:"girl",birthday:1505111954735},
        {name:"Lily",salary:12425,sex:"girl",birthday:1505711954735},
        {name:"Jeny",salary:87145,sex:"girl",birthday:1505811954735},
        {name:"Rose",salary:23845,sex:"girl",birthday:1905111954735},
        {name:"Tom",salary:86565,sex:"boy",birthday:1575111994735}
      ];
      $scope.arr=userInfo;
      /*自定义的模糊查询*/
      $scope.search="";
      $scope.searchFun=function(obj){
        if($scope.search!=""){
          if(obj.name.toLowerCase().indexOf($scope.search.toLowerCase())!=-1){
            return true;
          }else{
            return false;
          }
        }else{
          return true;
        }
      };
      /* 排序*/
      $scope.sort="name";
      $scope.revers=false;
      $scope.sortFun=function (column) {
        if($scope.sort==column){
          $scope.revers=!$scope.revers;
        }else{
          $scope.revers=false;
        }
        $scope.sort=column;
      };
      $scope.getClass=function(column){
        if($scope.sort==column){
          if($scope.revers==false){
            return "top"
          }else{
            return "bot"
          }
        }
      }
    })
  </script>
</head>
<body ng-app="myapp" ng-controller="myCtrl">
<input type="text"ng-model="search">
<table>
  <thead>
  <th>编号</th>
  <th ng-click="sortFun(&#39;name&#39;)">姓名<span ng-class="getClass(&#39;name&#39;)"></span></th>
  <th ng-click="sortFun(&#39;salary&#39;)">薪资<span ng-class="getClass(&#39;salary&#39;)"></span></th>
  <th ng-click="sortFun(&#39;sex&#39;)">性别<span ng-class="getClass(&#39;sex&#39;)"></span></th>
  <th ng-click="sortFun(&#39;birthday&#39;)">生日<span ng-class="getClass(&#39;birthday&#39;)"></span></th>
  </thead>
  <tbody>
  <tr ng-repeat="item in arr|filter:searchFun:value|orderBy:sort">
    <td>{{$index}}</td>
    <td>{{item.name|uppercase}}</td>
    <td>{{item.salary|currency:&#39;$&#39;}}</td>
    <td>{{item.sex}}</td>
    <td>{{item.birthday|date:&#39;yyyy-MM-dd&#39;}}</td>
  </tr>
  </tbody>
</table>
</body>
</html>
登入後複製

註:程式碼中尚有功能不夠完善的部分,有興趣的朋友可以自行加以完善。

上面是我整理給大家的,希望今後對大家有幫助。

相關文章:

透過webpack如何打包koa2 框架app,該怎麼做?

詳細解讀Vue元件化開發想法

#詳細解讀Vue.js中的元件使用方法以及作用?

以上是使用Angular如何實現三角箭頭標註功能的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!