2013-02-27 117 views
1

我有一個學生的記錄本的HTML代碼和它的工作好如何顯示在角JS

<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

你可以在孩子的UI元素使用NG-表演,並反覆在自己的NG-重複每個級別。注意:你不需要像if {{ student.subjects}} > 0(這不是一個有效的JS代碼btw)的東西。如果收集爲空,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>