【问题标题】:Angularjs filter based on http get基于http get的Angularjs过滤器
【发布时间】:2015-11-03 02:41:57
【问题描述】:

这是我的 Javascript 代码 如何实现基于此输入的搜索过滤器?我目前是 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>

【问题讨论】:

    标签: javascript angularjs html css angularjs-filter


    【解决方案1】:

    为了给你完整的过滤器,我需要了解你拥有的数据属性。我已经实现了一个基于 http get 的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>
    

    【讨论】:

    • 好吧,我实现了列表来显示结果。您可以在 .我认为这不是问题。
    • 感谢 ARYAN 你的英雄 ^_^ 我现在解决了太棒了
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-10-03
    • 1970-01-01
    • 1970-01-01
    • 2019-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多