2

我有这个用于学生记录的 html 代码,它运行良好

<li ng:repeat="student in students">
        <a href='#/student/{{ student.id }}'>{{ student.number }}</a>
</li>

但我有几个嵌套的细节层次,我想像这样展示

<ul>
<li ng:repeat="student in students">
            <a href='#/student/{{ student.id }}'>{{ student.number }}</a>
             if {{ student.subjects}} > 0
              //some indenting
                 <ul>
             <li ng:repeat="subject in subjects">
                        <a href='#/student/subject/{{ subject.id }}'>{{ subject.name }}</a>
                         if {{ subjects.assignments}} > 0
                         <ul>
                         <li ng:repeat="subject in subjects">
                        <a href='#/student/subject/assignment/{{ assignment.id }}'>{{ assignment.name }}</a>
                        <li>
                         </ul>
            <li>
             </ul>
        </li>
        </ul>

但我不知道角度语法,我该怎么做

4

1 回答 1

6

您可以在子 UL 元素上使用 ng-show,并在其自己的 ng-repeat 中迭代每个级别。注意:您不需要if {{ student.subjects}} > 0(顺便说一句,这不是有效的 JS 代码)之类的东西。如果集合为空,则 ngRepeat 不会迭代:

<ul>
  <li ng-repeat="student in students">
    <a href='#/student/{{ student.id }}'>{{ student.number }}</a>
    <ul ng-show="student.subjects && student.subjects.length">
      <li ng-repeat="subject in student.subjects">
        <a href='#/student/subject/{{ subject.id }}'>{{ subject.name }}</a>
          <ul ng-show="subject.assignments && subject.assignments.length">
            <li ng-repeat="assignment in subject.assignments">
              <a href='#/student/subject/assignment/{{ assignment.id }}'>{{ assignment.name }}</a>
            <li>
          </ul>
      <li>
    </ul>
  </li>
</ul>
于 2013-02-27T08:39:01.343 回答