您好,我在 mysql 中有 2 个表,我用 php(mysqli) 调用数据,所以我将这些数据放在带有 $scope.student= <?php echo json_encode( $student) ?>;
的 javascript var 中和 $scope.ratings= <?php echo json_encode( $ratings) ?>;
2个表有一个key id(ID_studen)
第一个表只有个人数据,第二个表有数据,所以我需要在此处按评分过滤并显示所有详细信息代码:
<div ng-app="" ng-controller="Ctrl">
<ul ng-repeat="student in students">
<li ng-repeat="rating in ratings (where student.tagid =ratings.tagid"> {{rating.note}}</li>
</ul>
</div>
检查 jsfiddle.net
最佳答案
您可以使用 $filter 请看下面的演示
app = angular.module("app", []);
app.controller("Ctrl", Ctrl);
function Ctrl($scope) {
$scope.students = [{
firstname: 'Buster',
lastname: 'Bluth',
tagid: '4134'
}, {
firstname: 'John',
lastname: 'McClane',
tagid: '9845'
}, {
firstname: 'Mister',
lastname: 'Spock',
tagid: '0905'
}];
$scope.ratings = [{
matter: 'Mathematics',
note: '12',
tagid: '4134'
}, {
matter: 'Biology',
note: '13',
tagid: '9845'
}, {
matter: 'Lenguage:',
note: '14',
tagid: '0905'
}];
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="Ctrl">
<ul ng-repeat="student in students">
<li ng-repeat="rating in ratings | filter : {tagid: student.tagid}">{{student.firstname}} {{student.lastname}} | {{rating.matter}} {{rating.tagid}}</li>
</ul>
</div>
关于javascript - Angularjs ng-repeat 按 id 过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27953331/