我有如下表所示的ng-repeat。我想要做的是在過濾器中傳遞t.genre
的值,但它不起作用。當價值得到時。它的過濾器是該值的名稱對象,並將其顯示在td
中。例如,值爲10
,那麼將顯示的名稱是爵士樂。如何通過ng-repeat在angularjs中生成的過濾器中傳遞值
注:當我改變t.genre
到10
輸出我得到的是:
1 simon 10 jazz 8 betty 20 jazz 14 archie 30 jazz 3 jumbo1 40 jazz
我要的是:
1 simon 10 jazz 8 betty 20 rock 14 archie 30 classic 3 jumbo1 40 metal
的index.html:
<tr ng-repeat="t in users">
<td>{{t.id}}</td>
<td>{{t.username}}</td>
<td>{{t.genre}}</td>
<td ng-repeat="typ in genre | filter:{ 'id':t.genre}:true">{{typ.name}}</td>
</tr>
和我controller.js:
function Ctrl($scope) {
$scope.users = [
{"id":1,"username":"simon","genre":"10"},
{"id":8,"username":"betty","genre":"20"},
{"id":14,"username":"archie","genre":"30"},
{"id":3,"username":"jumbo1","genre":"40"},
];
$scope.genre = [
{"id":10,"name":"jazz",},
{"id":20,"name":"rock",},
{"id":30,"name":"classic",},
{"id":40,"name":"metal"},
];
}
小提琴鏈接:提前http://jsfiddle.net/DharkRoses/dk247c3z/1/
任何HLP和建議表示感謝。
刪除過濾器,它會工作 –