Angularjs 基于动态ng模型的角表滤波

Angularjs 基于动态ng模型的角表滤波,angularjs,filter,Angularjs,Filter,我已经做了一些基本的角度滤波,但我遇到了一个小问题,我不知道如何解决它。我有一个带有输入标题的表格。我希望每个输入按该列筛选表。问题是试图将ng模型动态设置为相应的列名。我可以硬编码,但我需要动态编码。以前有人做过这样的事吗 编辑:有没有办法从ng repeat到search[key]或其他什么对key进行签名,因为我知道插值在ng模型中不起作用 代码如下: <table class="table table-striped"> <the

我已经做了一些基本的角度滤波,但我遇到了一个小问题,我不知道如何解决它。我有一个带有输入标题的表格。我希望每个输入按该列筛选表。问题是试图将ng模型动态设置为相应的列名。我可以硬编码,但我需要动态编码。以前有人做过这样的事吗

编辑:有没有办法从ng repeat到search[key]或其他什么对key进行签名,因为我知道插值在ng模型中不起作用

代码如下:

<table class="table table-striped">
                    <thead>
                        <tr ng-repeat="item in vm.students | limitTo:1">
                            <th ng-repeat="(key, val) in item">
                                {{key | format}}
                            </th>
                        </tr>
                        <tr ng-repeat="item in vm.students | limitTo:1">
                            <th ng-repeat="(key, val) in item">
                                <input type="text" ng-model='search.key'>
                            </th>
                            <tr>
                    </thead>
                    <tbody>
                        <tr ng-repeat="item in vm.students | filter:search.key ">
                            <td> {{item.id}}</td>
                            <td> {{item.car}}</td>
                            <td> {{item.payment_method}}</td>
                            <td> {{item.currency}}</td>
                            <td> {{item.city}}</td>
                        </tr>
                    </tbody>
                    <tfoot>
                    </tfoot>
                </table>

根据列对表进行排序的简单示例,这也可以通过使用自定义过滤器进行改进,这是一个基本示例

角JS var myApp=angular.modulemyyapp,[]; myApp.controllerfirstCtrl,函数$scope{ $scope.books=[{ 名称:Angular, 作者:詹姆斯, 价格:500, 年份:2012年 }, { 名称:爪哇, 作者:杜尔加, 价格:700, 年份:2001年 }, { 名称:HTML, 作者:拉胡尔, 价格:1500, 年份:2011年 }, { 名称:CSS, 作者:阿南德, 价格:2500, 年份:2002年 }, { 名称:节点, 作者:雷德, 价格:550, 年份:2015年 }]; }; 名称 奥图尔 价格 年 {{book.name} {{book.authur}} {{book.price}} {{book.year} 您可以使用方法填充列数组以生成表,然后使用搜索对象进行筛选:

图案对象可用于过滤对象上的特定特性 由数组包含。例如{name:M,phone:1}谓词将 返回属性名包含M和的项数组 物业电话,含1

以下是一个例子:

角度。模块'app',[] .controller'mainController',函数mainController$范围{ $scope.students=[ {姓名:'Aaron Judge',年份:'1',马克:98}, {姓名:'Ryan Zimmerman',年份:'two',马克:76}, {姓名:'Paul Goldschmidt',年份:'1',马克:87}, {姓名:'Mike Trout',年份:'two',马克:89}, {姓名:'Charlie Blackmon',年份:'1',马克:77}, {姓名:'Bryce Harper',年份:'three',马克:67}, {姓名:'Jose Altuve',年份:'two',马克:83}, ]; $scope.columns=Object.keys$scope.students[0]; $scope.search={}; }; 正文{padding top:50px;} 表输入{color:black;} 学生{{search} {{column}} {{学生[列]}
是的,但这是硬编码的,但我需要它是动态的,这意味着ng模型来自json密钥。