gpt4 book ai didi

javascript - Angularjs ng-repeat 按 id 过滤

转载 作者:行者123 更新时间:2023-11-30 17:06:18 25 4
gpt4 key购买 nike

您好,我在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com