[英]Angularjs filter not working with ng-repeat
當我使用函數更改過濾器值時,Angularjs過濾器無法與ng-repeat配合使用...我是angularjs的新手。
這些是我的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>
這些是我的控制器功能;
$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';
}
}
這就是過濾器不起作用的地方;
<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>
這是一張圖片;
我想使用配置文件按鈕過濾結果,但是'filterProfile'的值沒有改變...
請幫忙...
您應該做的是將模型帶入其過濾器選項,我想尤其是帶有這些數字的div。
現在我不太了解武器配置文件的願望清單,但是在配置文件中,您必須提供ng-model,例如ng-model = "profileSelected"
並添加到列表中
<ion-item ng-repeat="card in cardList | filter: profileSelected">
為了獲得更好的幫助,您可以創建一個Codepen嗎?
我不清楚您想要的最終產品是什么,但是我可以告訴您的不是定義自定義過濾器的方式。 格式類似於
var app = angular.module('buttonApp',[]);
app.filter('myFilter', function() {
return function(x) {
//filter goodness in here
}
})
您可以在以下網址找到過濾器的官方文檔:https://docs.angularjs.org/tutorial/step_11
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.