简体   繁体   English

AngularJS按属性过滤,使用Ng-Repeat NOT工作

[英]AngularJS filter by property using Ng-Repeat NOT working

I have an ng-repeat and it's repeating data successfully. 我有一个ng-repeat,它成功地重复数据。 Now, i want to filter the results by properties i type into an input box. 现在,我想通过输入框中输入的属性来过滤结果。 However, it either doesn't work at all or, if i try various things sometimes NOTHING gets displayed, at all. 然而,它要么根本不起作用,要么如果我尝试各种各样的东西,有时候什么都没有显示出来。 As you can see it's a work in progress and i've tried out a bunch of different stuff: hence why my code is inconsistent! 正如你所看到的那样,这是一项正在进行中的工作,我已经尝试了很多不同的东西:因此为什么我的代码不一致! Please, refrain from commenting on this as it's NOT CONSTRUCTIVE! 请不要对此发表评论,因为它不具有建设性!

             <tr ng-if="vm.detail == true">
                    <th><input type="text" ng-model="filter.TrusteeCustNum" /></th>
                    <th><input type="text" ng-model="filter.MchNumber" maxlength="4" class="input-    sm form-control" /></th>
                    <th><input type="text" ng-model="filter.ContractNumber" class="input-sm form-control" /></th>
                    <th><input type="text" ng-model="vm.PlanCode" maxlength="10" class="input-sm form-control" /></th>
                    <th><input type="date" ng-model="filter.PlanStatusDate" /></th>
                    <th><input type="text" ng-model="filter.PlanStatus" /></th>
                    <th><input type="date" ng-model="filter.PlanEffectiveDate" /></th>
                </tr>
            </thead>
            <tbody>
                <tr ng-repeat="plan in vm.PlanCodeInfo | filter: vm.PlanCode | orderBy:     vm.PlanCode" ng-if='vm.detail == true && vm.detailPlanCode'>
                    <td> {{plan.TrusteeCustNum}}</td>
                    <td>{{plan.CustomerNumber}}</td>
                    <td>{{plan.ContractNumber}}</td>
                    <td>{{plan.PlanCode }}</td>
                    <td>{{plan.PlanStatusDate | date: 'yyyy-MM-dd'}}</td>
                    <td>{{plan.PlanStatus}}</td>
                    <td> {{plan.PlanEffectiveDate | date: 'yyyy-MM-dd'}}</td>
                    <td><a href="">Rates</a></td>
                    <td><a href="">State Availability</a></td>
                </tr>

How can i get ANY filter to filter the results by the properties i'm using and sort them by those said properties? 我如何获得任何过滤器来过滤我正在使用的属性的结果,并按这些属性对它们进行排序?

If you want to filter by property PlanCode then filter should be an object with specified property: 如果PlanCode属性PlanCode进行过滤,则filter应该是具有指定属性的对象:

ng-repeat="plan in vm.PlanCodeInfo | filter:filterObj"

Where in HTML you define filter input with corresponding ngModel . 在HTML中,您可以使用相应的ngModel定义过滤器输入。 Of course you can use multiple properties to filter by. 当然,您可以使用多个属性进行筛选。 Here is an example of PlanCode and PlanStatusDate filters: 以下是PlanCodePlanStatusDate过滤器的示例:

<input type="text" ng-model="filterObj.PlanCode">
<input type="text" ng-model="filterObj.PlanStatusDate">

Does vm.PlanCode exist in your $scope? 你的$ scope中是否存在vm.PlanCode? Have you tried replacing it with a simple name like "planCode" and adding $scope.planCode = ''; 您是否尝试使用“planCode”这样的简单名称替换它并添加$ scope.planCode =''; to your $scope? 你的美元范围?

Just to see if it makes a difference? 只是为了看看它是否有所作为?

It would be helpful to see your model / scope. 查看您的模型/范围会很有帮助。

filter: filter.PlanCode is the code i needed to filter by planCode. filter:filter.PlanCode是我需要通过planCode过滤的代码。 Also, i have to change the ng-model to filter.PlanCode. 此外,我必须将ng-model更改为filter.PlanCode。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM