0
[
    [
         "x1", "x2" , 
         [
            ["n1", "n2"],["x3", "x4"],["x5", "x6"]
         ]
    ],
    [
         "y1", "y2"
    ],
    [
        "z1", "z2"
    ]
]

I want to access the x3 and x4 items , how to access with dustjs

1 Answer 1

2

It mostly depends on what you mean by "access", but here are some example templates that show you what happens if you use the special . reference, which in Dust means "the current iteration context"

{#.}
  Item {.} 
{/.}

Output:

Item x1,x2,n1,n2,x3,x4,x5,x6 Item y1,y2 Item z1,z2

By iterating one level into the current context, you see that the top-level array elements are iterated on. One step deeper:

{#.}{#.}
  Item {.} 
{/.}{/.}

Output:

Item x1 Item x2 Item n1,n2,x3,x4,x5,x6 Item y1 Item y2 Item z1 Item z2 

Notice how the depth at which we traverse nested arrays increases the more levels of context you tell Dust to inspect. So for your above example, four levels will suffice:

{#.}{#.}{#.}{#.}
  Item {.} 
{/.}{/.}{/.}{/.}

Output:

Item x1 Item x2 Item n1 Item n2 Item x3 Item x4 Item x5 Item x6 Item y1 Item y2 Item z1 Item z2 
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.