Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/474.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Ng单击并显示Ng AngularJS_Javascript_Html_Arrays_Json_Angularjs - Fatal编程技术网

Javascript Ng单击并显示Ng AngularJS

Javascript Ng单击并显示Ng AngularJS,javascript,html,arrays,json,angularjs,Javascript,Html,Arrays,Json,Angularjs,我有一个字典列表,我想显示每个教室的所有学生及其详细信息。 这是HTML: <div ng-app="myApp" ng-controller="myCtrl"> <div class="classrooms-details" ng-show="Students"> <table class="table table-striped"> <thead> <tr> <t

我有一个字典列表,我想显示每个教室的所有学生及其详细信息。

这是HTML:

<div ng-app="myApp" ng-controller="myCtrl">

<div class="classrooms-details" ng-show="Students">
    <table class="table table-striped">
        <thead>
         <tr>
          <th>First name</th>
          <th>Last name</th>
          <th>Gender</th>
          <th>Birthday</th>
         </tr>
         </thead>
         <tbody>
     <tr ng-repeat="classroom in classrooms">
       <td>{{classroom.student.first_name}}</a></td>
       <td>{{classroom.student.last_name}}</td>
       <td>{{classroom.student.gender}}</td>
       <td>{{classroom.student.birthday}}</td>
      </tr>
     </tbody>
     </table>
</div>

<table class="table table-striped">
    <thead>
     <tr>
      <th>Classroom</th>
      <th>School</th>
      <th>Academic year</th>
     </tr>
     </thead>
     <tbody>
     <tr ng-repeat="classroom in classrooms">
       <td><a href="#" ng-click="showStudents">{{classroom.classroom}}</a></td>
       <td>{{classroom.school.school_name}}</td>
       <td>{{classroom.academic_year}}</td>
      </tr>
     </tbody>
   </table>

</div>
我不知道如何访问“学生”值,我希望只有在单击教室名称时才能显示学生的详细信息


我如何才能做到这一点?

您只需将特定教室设置为“活动”教室,并显示其中的学生。最简单的方法是:

查看

<tr ng-if="activeClassroom" ng-repeat="student in activeClassroom.students">
  <td>{{student.first_name}}</a></td>
  <td>{{student.last_name}}</td>
  <td>{{student.gender}}</td>
  <td>{{student.birthday}}</td>
</tr>

回答得好!谢谢:)
<tr ng-if="activeClassroom" ng-repeat="student in activeClassroom.students">
  <td>{{student.first_name}}</a></td>
  <td>{{student.last_name}}</td>
  <td>{{student.gender}}</td>
  <td>{{student.birthday}}</td>
</tr>
<tr ng-repeat="classroom in classrooms">
  <td><a href="#" ng-click="setActiveClassroom(classroom)">{{classroom.classroom}}</a></td>
  <td>{{classroom.school.school_name}}</td>
  <td>{{classroom.academic_year}}</td>
</tr>
$scope.activeClassroom = null;

$scope.setActiveClassroom = function (classroom) {
  $scope.activeClassroom = classroom;
};