Angularjs總結(二)過濾器使用

來源:互聯網
上載者:User

標籤:

html頁面:

 1 <table> 2     <thead> 3         <tr> 4             <td class="td">序號</td> 5             <td class="td ">規劃用途</td> 6         </tr> 7     </thead> 8     <tbody> 9         <tr ng-repeat="FW in FWlist ">10             <td class="td" ng-bind="$index+1">1</td>11             <td class="td ">{{FW.GHYT|NAME}}</td>12         </tr>13     </tbody>14 </table>

過濾器:

 1 define([‘angular‘], function (ng) { 2     ‘use strict‘; 3     ng.module(‘index-filters‘, []) 4  5         .filter(‘price‘, [function () { 6  7             return function (num) { 8  9                 return ‘¥ ‘ + num;10 11             };12 13         }])14         .filter(‘gender‘, [function () {15 16             return function (gender) {17 18                 switch (gender) {19 20                     case 1: return ‘男‘;21 22                     case 2: return ‘女‘;23 24                     case 0: return ‘‘;25 26                 }27 28             }29 30         }])31         .filter(‘NAME‘, [function () {32 33             return function (YWLX) {34 35                 if (YWLX == null) return "";36 37 38                 var str = YWLX;39 40                 if (YWLX.length > 10) {41 42                     str = YWLX.substring(0, 10) + "...";43 44                 }45                 return str;46 47             }48 49         }])50         .filter(‘stateimgurl‘, [function () {51 52             return function (state) {53 54                 switch (state) {55 56                     case ‘正常‘: return ‘../img/normal.png‘;57 58                     case ‘預警‘: return ‘../img/warning.PNG‘;59 60                     case ‘超期‘: return ‘../img/timeout.png‘;61                 }62 63             }64 65         }])66         .filter(‘GHYTToName‘, [‘audit-service‘, function (auditservice) {67             //audit-service  服務68             var tempData = [];69             auditservice.getParameter("房屋用途").success(function (sjlxlist) {70 71                 tempData = sjlxlist;72 73             });74 75             return function (id) {76                 for (var i = 0; i < tempData.length; i++) {77 78                     if (tempData[i].Code == id) {79 80                         return tempData[i].Name;81                     }82                 }83             }84         }])85 })

html頁面所需的控制器:

1 define([‘index-filters‘], function (app) {2     app.controller(‘index-controller‘, [‘$rootScope‘, ‘$scope‘, ‘$location‘, ‘$cookies‘,3        function ($rootScope, $scope, $location, $cookies) {4 5        }])6 })

 

Angularjs總結(二)過濾器使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.