2017-12-15 12 views
0

私はangularjsフィルタを作成しようとしています。私は3つの属性をフィルタリングしています。最初の2つはコンパレータfalseで、最後はコンパレータtrueです。カスタムフィルタを作成せずに可能ですか?私は以下で試したが、それはエラーをスローする。複数のフィルタを持つコンパレータを使用するangularjsフィルタ

|ここ

filter : 
    { 
     'PatientFullName' : vm.headerService.searchText, 
     'Archived' : vm.headerService.Archived, 
     'PhysicianID' : {vm.headerService.selectedPhysician.PhysicianID,true} 
    } 

ここ

<div class="col-sm-6 col-md-4" ng-repeat="patient in vm.patientlist | orderBy: vm.headerService.currentSort.orderBy:vm.headerService.currentSort.sortDescending 
    | filter : 
    { 
     'PatientFullName' : vm.headerService.searchText, 
     'Archived' : vm.headerService.Archived, 
     'PhysicianID' : {vm.headerService.selectedPhysician.PhysicianID,true} 
    }"> 

全体htmlですエラー

angular.js:14794 Error: [$parse:syntax] Syntax Error: Token '.' is unexpected, expecting [}] at column 263 of the expression [vm.patientlist | orderBy: vm.headerService.currentSort.orderBy:vm.headerService.currentSort.sortDescending | filter : { 'PatientFullName' : vm.headerService.searchText, 'Archived' : vm.headerService.Archived, 'PhysicianID' : {vm.headerService.selectedPhysician.PhysicianID,true} }] starting at [.headerService.selectedPhysician.PhysicianID,true} }].

答えて

1

{vm.headerService.selectedPhysician.PhysicianID,true}が正しいオブジェクトではありませんです。 comparatorの異なる値によって、あなたかもしれチェーンフィルタリングフィルタリングを実行するには、次の

<div class="col-sm-6 col-md-4" ng-repeat="patient in vm.patientlist | orderBy: vm.headerService.currentSort.orderBy:vm.headerService.currentSort.sortDescending 
| filter : 
{ 
    'PatientFullName' : vm.headerService.searchText, 
    'Archived' : vm.headerService.Archived 
} 
| filter : 
{   
    'PhysicianID' : vm.headerService.selectedPhysician.PhysicianID 
}: true"> 

をしかし、より優れたコントローラのメソッドの中にそれを書き換えます。読みやすさを向上させます:

<div class="col-sm-6 col-md-4" 
ng-repeat="patient in vm.patientlist | 
      orderBy: vm.headerService.currentSort.orderBy 
        : vm.headerService.currentSort.sortDescending 
      |filter : vm.myFilteringMethod"> 
関連する問題