linkedin / linkedin/dustjs

Problem accessing outer AND inner indexes inside nested arrays at the same time

Open
#781 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
2.9k
Forks
461
PR merge metrics
No merged PRs in 30d

Description

Hi, I've got nested arrays such as this one:

"outer" : [
{
"inner": [
{},
{}
]
},
{
"inner": [
{},
{}
]
}
]

I neeed to generate an output like that one:

outer[0].inner[0]
outer[0].inner[1]
outer[1].inner[0]
outer[1].inner[1]

My problem is that once I'm inside the inner context, I do not know the outer index. $idx gives me the index of inner. Is there a way for me to access the outer index inside the inner context?

Template example:
{#outer}
{#inner}
outer[???].inner[{$idx}]
{/inner}
{/outer}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start from the nested-array template example in the issue and determine whether Dust supports accessing the outer array index from the inner context. Verify the behavior against the expected four output paths; the work is done when the template can produce those paths or the supported limitation is documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
web-dev
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.