0

In app.js, I pass back 2 arrays of the same size to the client.

Is it possible to do something like this?

{{#each arrayOne}}
<Li>this </Li>
<Li> {{@index : arrayTwo}} </Li>
{{/each}}
1
  • 1
    You'll probably have to prepare your datastructures to map more closely to your use case as Handlebars isn't supposed to be a scripting language. Commented Nov 28, 2013 at 21:27

1 Answer 1

1

You should avoid complex logic in your view templates. Instead, I'd recommend having a controller do the merging job for you.

That way you'd untangle the view, since its more descriptive of what you're going to display, and your controller clearly states the intent to render different data in a combined manner.

e.g

model.arr = arrayOne.map(function (item, i) {
  return {
    i1: arrayOne[i],
    i2: arrayTwo[i]
  };
});

Then your view becomes much simplified

{{#each arr}}
<Li>{{arr.i1.thing}}</Li>
<Li>{{arr.i2.thingie}}</Li>
{{/each}}

Obviously you should improve this further by only returning the relevant properties in your map callback.

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

1 Comment

I looked into map and it looks exactly like what I need. Thanks for your help.

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.