3

So im trying to render a dust template with two separate arrays. My data is something like:

{
    array1: [5, 10, 20],
    array2: [10, 20, 40]
}

And my dust template looks like:

{#array1}
<div class="span2">
  <input type="number" value={.}></div>
<div class="span2">
  <input type="number" value={array2[{$idx}]}></div>
</div>{~n}
{/array1}

It displays the elements from array1 fine, but all the inputs for array2 are blank. I'm using dust-full-1.2.2.js linkedIn fork. What should I do to be able to display the values of array2?

1

3 Answers 3

6

The Dust way to do this is to change the data (if that's possible):

{
    numbers: [
        {val1: 5, val2: 10},
        {val1: 10, val2: 20},
        {val1: 20, val2: 40}
    ]
}

Then your template would look like this:

{#numbers}
  <div class="span2">
    <input type="number" value="{val1}"></div>
  <div class="span2">
    <input type="number" value="{val2}"></div>
  </div>
{/numbers}
Sign up to request clarification or add additional context in comments.

1 Comment

I've seen in the documentation that its possible to access elements of an array that you pass to dust, so why should I need to change my data? I can do that but I would prefer not to.
0

Please let me know if this could work for you. http://jsfiddle.net/yXx5L/3/

Im using a helper to fill the second text box value without changing the data format.

value={#counterpart i=$idx}{ele}{/counterpart}

Comments

0

change the context to Array2. Add {#array2[...]}

Refer to Explicit context setting here : https://github.com/linkedin/dustjs/wiki/Dust-Tutorial

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.