【发布时间】:2017-01-12 22:01:50
【问题描述】:
我刚开始学习 Angular JS,我正在准备一个测试库系统,并且对 ng-repeat 有一个小问题
我有 2 张桌子。一个存储有关书籍的详细信息,另一个存储借书的学生。
表 1-book_id, book_name, borrowed, student_id
表 2 - book_id, student_ name, student_id
有 2 个单独的函数从上面的每个表中获取所有详细信息。
下面的代码显示了从第一个表中抓取的所有书籍
<div class=”available” ng-repeat="book in books">{{book.book_name}}</div>
我想做的是
If borrowed == 1
更改 class="not_available" 并将 student_name 和 book_name 添加到需要从包含学生详细信息的学生中获取的 div 中。
JS 代码
function studentsController($scope,$http) {
$scope.students = [];
$http.get('<?php echo site_url('angularjs/get_students'); ?>').success(function($data){ $scope.students=$data; });
}
function booksController($scope,$http) {
$scope.books = [];
$http.get('<?php echo site_url('angularjs/get_books'); ?>').success(function($data){ $scope.books=$data; });
}
我确实尝试了filter 和ng-if,但我无法实现上述目标
任何帮助将不胜感激
【问题讨论】:
-
你也可以发布你的javascript吗?您在 book 对象中有哪些信息?要更改您使用 ng-class 的类。将
class="available"替换为ng-class="book.borrowed == 1 ? 'not_available' : 'available'" -
@Razzildinho 图书对象具有`id、book_name、借用、student_id` 详细信息....我试试 ng-class 的东西 :)
-
查看我的答案
标签: angularjs