AngularJS ng-repeat ID过滤器 [英] Angularjs ng-repeat filter by id
问题描述
我在mysql中有2个表,我用php(mysqli)调用数据,所以我将此数据放在$scope.student= <?php echo json_encode( $student) ?>;
和$scope.ratings= <?php echo json_encode( $ratings) ?>;
的javascript var中,2个表具有键id(ID_studen)
hi i have 2 tables in mysql, i call the data with php(mysqli), so i put this data in javascript var with $scope.student= <?php echo json_encode( $student) ?>;
and $scope.ratings= <?php echo json_encode( $ratings) ?>;
2 tables have a key id(ID_studen)
第一个表只有一个个人数据,第二个表有数据,因此我需要过滤并通过此处的代码显示所有详细信息:
The first table have only a personal data, and the second have datails, so i need filter and show all details by ratings here code:
<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,请参见下面的演示
You can use $filter please see demo below
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>
这篇关于AngularJS ng-repeat ID过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!