2014-11-06 4 views
0

TableController의 데이터 구조를 감안할 때 : 당신의 목표는 같은 테이블을 만들 수 있다면각도 중첩 된 NG 반복 테이블

var obj = { 
    titles : { 
    title: 'Title' 
    , data : ['a title' , 'another title', 'look a title', 'and another'] 
    } 
, other-prop : { 
    title: 'Other Prop' 
    , data : [3030, 849875, 8888, 48484] 
    } 
} 

this.obj = obj; 

가 :

table 
    thead 
    tr 
     th "Title" 
     th "Other Prop" 

    tbody 
    tr 
     td "a title" 
     td "3030" 
    tr 
     td "another title" 
     td "849875" 
    tr 
     td "look a title" 
     td "8888" 
    tr 
     td "and another" 
     td "48484" 

어떻게 당신이 NG-반복 구조 것입니까? 저를주고있다

div [controller="TableController as table"] 

table 
    thead 
    tr 
     th [ng-repeat = "(key, value) in table.obj"] 

    tbody 
    tr [ng-repeat = "(key, value) in table.obj" 
     td [ng-repeat="(key, val) in table.obj track by $index"] "{{value.data}}" 

...

table 
    thead 
    tr 
     th "Title" 
     th "Other Prop" 
    tbody 
    tr 
     td "['a title' , 'another title', 'look a title', 'and another']" 
     td "[3030, 849875, 8888, 48484]" 
    tr 
     td "['a title' , 'another title', 'look a title', 'and another']" 
     td "[3030, 849875, 8888, 48484]" 

을 ... 그래서 가까운 해요하지만 난 좀 .. 개체가 올바른 방향으로 나열하지 못할 : 지금은 있습니다.

누구나?

+1

더 나은 관계를 위해 모델을 사전 처리하지 않으면 좋은 방법이 없습니다. 데이터를 다르게 구성해야합니다. –

답변

1

당신은 table['other-prop'].data 배열로 직접 인덱싱하여 작업을 수행 할 수 있습니다

div [controller="TableController as table"] 

table 
    thead 
     tr 
      th [ng-repeat = "(key, value) in table.obj"] 

    tbody 
     tr [ng-repeat = "(key, value) in table.obj.data" 
      td "{{value}}" 
      td "{{table['other-prop'].data[$index]}}" 

그것은 작동하지만이 목록의 임의의 수에 확장 성이 아니다.

브라이언 노아 (Brian Noah)의 제안을 받아 렌더링하기 쉬운 구조로 데이터를 전처리해야합니다.

+0

Brian Noah의 제안입니다. 고마워. –