本文實(shí)例講述了Angularjs過濾器實(shí)現(xiàn)動態(tài)搜索與排序功能。分享給大家供大家參考,具體如下:
利用angularjs實(shí)現(xiàn)動態(tài)的插入以及利用過濾器進(jìn)行數(shù)據(jù)的搜索以及排序.
<!DOCTYPE html><html lang="en" ng-app="myApp"><head> <meta charset="UTF-8"> <title>m.survivalescaperooms.com AngularJS過濾器測試</title></head><body ng-controller="app"> <table> <tr> <td ng-click="sort('name')">姓名</td> <td ng-click="sort('age')">年齡</td> </tr> <tr ng-repeat="arr1 in arr1"> <td>{{arr1.name}}</td> <td>{{arr1.age}}</td> </tr> </table> <input id="wei" type="text" ng-focus="concentrate()" > <input type="button" ng-click="search()" value="搜索"></body><script src="angular.min.js"></script><script src="jquery.js"></script> <script> // var wei = document.getElementById("wei"); // console.log(wei); // setTimeout(function(){ // $("#wei").attr("disabled",false); // },3000); var m=angular.module("myApp",[]); m.controller("app",["$scope","$filter",function($scope,$filter){ var arr=[ {"name":"豬","age":20}, {"name":"小豬","age":23}, {"name":"大貓","age":227}, {"name":"老虎","age":29}, {"name":"中虎","age":29}, {"name":"老虎","age":39}, {"name":"老貓","age":47}, {"name":"熊貓","age":29}, {"name":"樹懶","age":27}, {"name":"獅子","age":59} ]; $scope.arr1=arr; //實(shí)現(xiàn)查詢功能 var isopen=true; $scope.sort=function(str){ $scope.arr1=$filter("orderBy")($scope.arr1,str,isopen); isopen=!isopen; //console.log(isopen); }; $scope.concentrate=function(){ console.log("已聚焦"); } //實(shí)現(xiàn)查詢功能 $scope.search=function(){ console.log(11); $scope.arr1=$filter("filter")(arr,document.getElementById("wei").value); } }]); </script></html>運(yùn)行效果:

更多關(guān)于AngularJS相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《AngularJS指令操作技巧總結(jié)》、《AngularJS入門與進(jìn)階教程》及《AngularJS MVC架構(gòu)總結(jié)》
希望本文所述對大家AngularJS程序設(shè)計有所幫助。
|
新聞熱點(diǎn)
疑難解答