2017-02-16 5 views
0

이 질문 세트를 반복하고 각도로 템플릿을 작성할 수 있어야하는 데이터 구조 (아래 샘플 제공)가 있습니다. 각각 「질문」이 구성 가지고모서리 1.x를 사용한 재귀 또는 복잡한 템플릿

{ 
    id: 2, // unique id 
    label: 'some label', // any label 
    type: 'input', // the type of html element 
    options: [], // other questions are nested in here (recursive) 
    children: [] // other questions are nested in here (recursive) 
} 

상술 한 바와 같이이, 타입 HTML 요소의 유형 및 optionschildren 차이를 설명 options 렌더링 questions 세트가 동일한 라인의 표시는 것이다 부모 질문의 경우 questionschildren 인 경우 한 줄 아래에 약간의 여백이 표시됩니다.

기본적인 내용이 ng-repeat인데 충분하지 않다는 것을 알고 있습니다. (이해할 때부터) 여기에 충분하지 않습니다. 그리고 이런 종류의 데이터를 템플릿 화하는 방법에 대해 궁금합니다. 구조.

미리 도움을 청합니다.

[ 
    { 
     id: 1, 
     label: 'something', 
     type: 'text', 
     options: [ 
      { 
       id: 2, 
       label: 'another', 
       type: 'text', 
       options: [], 
       children: [] 
      } 
     ], 
     children: [ 
      { 
       id: 83, 
       label: 'cool', 
       type: 'input', 
       options: [], 
       children: [] 
      }, 
      { 
       id: 121, 
       label: 'another cool thing', 
       type: 'label', 
       options: [ 
        { 
         id: 451, 
         label: 'only a label', 
         type: '', 
         options: [], 
         children: [ 
          { 
           id: 901, 
           label: 'a cool info', 
           type: 'label', 
           options: [], 
           children: [] 
          } 
         ] 
        } 
       ], 
       children: [] 
      } 
     ] 
    }, 
    { 
     id: 27, 
     label: 'some text', 
     type: 'label', 
     options: [ 
      { 
       id: 541, 
       label: 'hey there', 
       type: 'label', 
       options: [], 
       children: [] 
      } 
     ], 
     children: [ 
      { 
       id: 761, 
       label: 'hi there', 
       type: 'checkbox', 
       options: [], 
       children: [] 
      }, 
      { 
       id: 165, 
       label: 'cool', 
       type: 'text', 
       options: [ 
        { 
         id: 1090, 
         label: 'neat', 
         type: 'input', 
         options: [], 
         children: [ 
          { 
           id: 9891, 
           label: 'tell me', 
           type: 'textarea', 
           options: [], 
           children: [] 
          } 
         ] 
        } 
       ], 
       children: [] 
      } 
     ] 
    } 
]; 
+0

옵션을 만들기 위해 골짜기를 반복하는 항목의 종류에 따라 ng-repeats를 적용하고 ng-class를 적용해야하고 어린이는 CSS 클래스를 적용하는 것처럼 보일 것입니다. –

+0

네, 그게 원래 가지고 있던 것이지만 다음과 같은 문제는 해결하지 못합니다 : --------- 1) 중첩 된 ng 반복은 작성한 수준만큼 우수합니다. 따라서 왜 이렇게 다른 방법이 있는지 궁금 해서요 ------- 2) ng-class는 다른 유형의 html 요소를 설명하지 않습니다. ng-switch를 사용하고 거기에있는 모든 것들을 생각하고 있었지만 다른 방법이 있습니까? – Detuned

답변

1

내가 사용하는 것이 좋습니다 것 NG-경우 즉시 외부 HTML 템플릿을 대신 겨-클래스를 호출 할 수 있도록 :

여기에 샘플 데이터 구조입니다. 옵션이나 자식이 존재할 경우 다른 ng-repeat 내부에 포함되도록 템플릿을 조정할 수 있으므로 배열/객체의 끝까지 반복 할 수 있습니다.

+0

우연히 어떤 사례가 있습니까? – Detuned