[英]Angularjs filter not working with ng-repeat
Angularjs filter not working with ng-repeat when I change filter value with a function... I am new to angularjs. 当我使用函数更改过滤器值时,Angularjs过滤器无法与ng-repeat配合使用...我是angularjs的新手。
These are my html buttons from which the filter value must be changed with the function on 'ng-click'; 这些是我的html按钮,必须使用“ ng-click”功能更改过滤器值;
<span>
<a class="button button-stable" ng-class="class('static')"
ng-click="activate('static','','')">
All
</a>
</span>
<span ng-repeat="profiles in cardList | unique:'profile'">
<a class="button button-stable" ng-class="class($index)"
ng-click="activate($index,profiles,profiles.profile);">
{{profiles.profile}}
</a>
</span>
These are my controller functions; 这些是我的控制器功能;
$scope.cardList = [
{id: 1, serial_number: '35986580', card_number: 'BG9S8W7DJSKLA9', profile: '512', expiry_date: '5-1-2017'},
{id: 2, serial_number: '35986581', card_number: 'ASLWODS6F5812H', profile: '512', expiry_date: '5-1-2017'},
{id: 3, serial_number: '35986582', card_number: '9A5S218LSKJBMC', profile: '768', expiry_date: '5-1-2017'},
{id: 4, serial_number: '35986583', card_number: 'XLCKDIGOSJS092', profile: '1024', expiry_date: '5-1-2017'},
{id: 5, serial_number: '35986584', card_number: 'XKSODKO0CNJSUW', profile: '1024', expiry_date: '5-1-2017'},
{id: 6, serial_number: '35986585', card_number: 'PLHG0G9M746172', profile: '2048', expiry_date: '5-1-2017'},
{id: 7, serial_number: '35986586', card_number: '5DF888F9EGVNDJ', profile: '2048', expiry_date: '5-1-2017'},
{id: 8, serial_number: '35986587', card_number: 'D6F5G49ILMA9SF', profile: '4096', expiry_date: '5-1-2017'}
];
$scope.class = function(index, item){
if ($scope.selected == index){
return 'button-dark active';
} else {
$scope.staticAll = '';
return '';
}
}
$scope.activate = function(index, item, profile){
if (index != 'static'){
$scope.selected = index;
$scope.filterProfile = profile;
$scope.staticAll = '';
} else {
$scope.selected = 'static';
$scope.filterProfile = '';
$scope.staticAll = 'button-dark active';
}
}
And this is where the filter is not working; 这就是过滤器不起作用的地方;
<tr ng-repeat="card in cardList | filter: filterProfile">
<td class="center">{{card.profile}}</td>
<td class="center">{{card.expiry_date}}</td>
<td class="center"><a class="button button-medium button-energized">Assign</a></td>
</tr>
This is an image; 这是一张图片;
I want to filter the results with profile buttons, but the value of 'filterProfile' is not changing... 我想使用配置文件按钮过滤结果,但是'filterProfile'的值没有改变...
Please help... 请帮忙...
What you should do is take a model to its filter option, I imagine that the divs with those numbers in particular. 您应该做的是将模型带入其过滤器选项,我想尤其是带有这些数字的div。
Now I do not quite understand as a weapon profiles wishlist but, in their profiles, you must give ng-model such as ng-model = "profileSelected"
现在我不太了解武器配置文件的愿望清单,但是在配置文件中,您必须提供ng-model,例如
ng-model = "profileSelected"
And to your list, add 并添加到列表中
<ion-item ng-repeat="card in cardList | filter: profileSelected">
for better help, you can create a codepen? 为了获得更好的帮助,您可以创建一个Codepen吗?
I'm not so clear what you want for an end product, but I can tell you that's not how custom filters are defined. 我不清楚您想要的最终产品是什么,但是我可以告诉您的不是定义自定义过滤器的方式。 the format is something like
格式类似于
var app = angular.module('buttonApp',[]);
app.filter('myFilter', function() {
return function(x) {
//filter goodness in here
}
})
You can find the official documentation for filters here https://docs.angularjs.org/tutorial/step_11 您可以在以下网址找到过滤器的官方文档:https://docs.angularjs.org/tutorial/step_11
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.