0

I'm struggling a bit on a common javascript issue, mostly because I don't know the key words to find the solution in Google. What I would like to do in pure javascript :

var obj = {label: 'Name', type: 'text', position: 0};
var name = 'label';

var temp = obj."name" // = obj.label = Name

And use it in meteorJS template :

data = [ 
  {
     "Name" : "Task 1",
     "CreationDate" : ISODate("2014-06-03T19:47:48.252Z"),
     "EndDate" : ISODate("2014-07-03T19:47:48.252Z")
  }, 
  {
     "Name" : "Task 2",
     "CreationDate" : ISODate("2014-06-04T19:47:48.252Z"),
     "EndDate" : ISODate("2014-07-04T19:47:48.252Z")
  }
}

columns = [
        {label: 'Name'},
        {label: 'Creation Date'},
        {label: 'End Date'}
    ]

{{#each data}}
  <tr>
    {{#each columns}}
      <td>{{data.label}}</td>
    {{/each}}
  </tr>
{{/each}}
3

1 Answer 1

0

So for my first question (pure javascript syntax) its ok. Thanks

var obj = {label: 'Name', type: 'text', position: 0};
var name = 'label';
var temp = obj[name];  //Works fine

For my second question, this way is working (inspired by How to access outer {{#each}} collection value in the nested loop) :

{{#each data}}
    <tr>
        {{#each columns}}
            <td>{{attr .. label}}</td>
        {{/each}}
    </tr>
{{/each}}

Template.worksheets.helpers({
    attr : function (outItem, inItem) {
        return outItem[inItem];
    }
});

But its a bit ugly ...

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

1 Comment

You should ask a new question instead of asking a new question as an answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.