2015-11-03 108 views
0

这里是我的Javascript代码我如何实现基于此输入的搜索过滤器?我目前对angularjs很陌生。基于http的Angularjs过滤器得到

var app = angular.module('myApp', ['angularUtils.directives.dirPagination']); 
        app.controller('workShiftController', function($scope, $http) { 
         $http.get("getWorkShiftArchiveJson?workshift_id="+getCookie('shiftId')) 
         .success(function (response) {$scope.workshift_archive = response; 

         }); 
        }); 

这里是我的HTML代码

<div ng-app="myApp" ng-controller="workShiftController"> 
    <center><h1 style="font-size:2em;">Workshift Archive History</h1></center> 
    <hr> 
     <table class="table table-striped" at-table at-paginated at-list="filteredList" at-config="config"> 
     <thead> 
      <tr> 
       <th>Work Shift Name</th><th>First Name</th><th>Middle Name</th><th>Last Name</th> 
       <th>Hours Per Day</th><th>Start Time</th><th>End Time</th><th>Period From</th><th>Period To</th> 
      </tr> 
     </thead> 
     <tbody> 
      <tr dir-paginate="x in workshift_archive | itemsPerPage: 10 "> 
      <td>{{x.workshift_name}}</td> 
      <td>{{ x.first_Name }}</td> 
      <td>{{ x.middle_Name }}</td> 
      <td>{{ x.last_Name }}</td> 
      <td>{{ x.hours_per_day }}</td> 
      <td>{{ x.start_time }}</td> 
      <td>{{ x.end_time }}</td> 
      <td>{{ x.period_from }}</td> 
      <td>{{ x.period_to }}</td> 
      </tr> 
     </tbody> 
     </table> 
    <dir-pagination-controls></dir-pagination-controls> 
    </div> 

回答

1

为了让您充分实现过滤我需要知道数据属性你。我已经实现了一个基于http get.you的sample plunker过滤器,可以按名字过滤。

html实施

<ul ng-controller="MyController as controller"> 
    <input type="text" placeholder='enter first name' ng-model="search.first_Name"> 

<table class="table table-striped" at-table at-paginated at-list="filteredList" at-config="config"> 
    <thead> 
     <tr> 
      <th>Work Shift Name</th><th>First Name</th><th>Middle Name</th><th>Last Name</th> 
      <th>Hours Per Day</th><th>Start Time</th><th>End Time</th><th>Period From</th><th>Period To</th> 
     </tr> 
    </thead> 
    <tbody> 
     <tr ng-repeat="x in controller.mydata| filter:search"> 
     <td>{{x.workshift_name}}</td> 
     <td>{{ x.first_Name }}</td> 
     <td>{{ x.middle_Name }}</td> 
     <td>{{ x.last_Name }}</td> 
     <td>{{ x.hours_per_day }}</td> 
     <td>{{ x.start_time }}</td> 
     <td>{{ x.end_time }}</td> 
     <td>{{ x.period_from }}</td> 
     <td>{{ x.period_to }}</td> 
     </tr> 
    </tbody> 
    </table> 

+0

你好,这是我的数据属性http://plnkr.co/edit/iO3yERm8VW7HvhCYI0CU –

+0

以及我实现为列表中显示的结果。你可以改变你的表格视图。我认为这不是问题。 – 2015-11-03 03:08:37

+1

感谢ARYAN您的英雄^ _ ^我现在已经解决了真棒 –