0

Given a data structure in TableController:

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;

if your goal was to create a table like:

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"

How would you structure the ng-repeats? Right now I have:

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}}"

Which is giving me...

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]"

... So I'm close but I cant get... the objects to list in the correct direction.

Anyone?

1
  • 1
    there's no really good way unless you preprocess your model to relate better. you would have to form your data differently. Commented Nov 6, 2014 at 23:45

1 Answer 1

1

You can do it by indexing directly into the table['other-prop'].data array:

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]}}"

It will work but it's not scalable to an arbitrary number of lists.

For that you would need to take Brian Noah's suggestion and preprocess the data into a structure that's easier to render out.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.