-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nested {{each}} loops: context/scope is messed up when current iteration values are equal #1300
Comments
Yes, this looks like a bug. I have changed the jsfiddle a little to make it clearer: |
This is being caused by this piece of code... If the previous context is the same as the current context, then the context is not pushed onto the In your case, since the strings are equal in the different This was originally added so that helpers like This is just information I discovered while researching how the context changes in block helpers... I don't have any ideas for a fix yet. |
I have thought about a fix for this bug quite often now, but I don't have any good idea, but I have a workaround... |
hello guys i am learning node/express right now, the code above wont work for me i am using express-handlebars, can you help me? Is this possible with express-handlebars? here's my code. the gpareaData is iterating but the branch is not
|
@bjmercado how does your context data look like?
|
@atomictag so i'll just program to format my data?, im using mysql for the database this is the branch and this is the gpAreaData |
hey guys i just solve the problem i just put ../ in the branch `{{#each gpareaData}} {{desc}} {{#each ../branch}} {{branch_desc}} {{/each}} {{/each}}` |
its my code but the control is not even entering into the nester each. I want to know why ? |
Closing due to inactivity. I think this is a valid issue, but it can be worked around by using block parameters. Fixing it would be a breaking change, so I'd rather keep this a known bug at the moment. It should be documented though. |
Think I've encountered a bug. If you have a nested each (i.e., an each within an each), in any iteration where the parent loop's current value is equal to the child loop's current value, the context/scoping appears to be off. To illustrate:
I recognize that's confusing to follow, so I've made two examples that examine the issue through another lense. See https://jsfiddle.net/9D88g/73/ (where we try to access the same variable we're iterating through; if the scope is messed up, outputs an X) and https://jsfiddle.net/9D88g/74/ (where we try to access another variable). In the second example, if you change the conditional and output where I write
../../word
to../word
, you'll notice it works the opposite way.I've examined this further and the issue persists for any nested each where the current values of the parent and child are equal. The examples I show use the same array, but if we use arrays with different values the problem still occurs.
This is not an issue in Handlebars <4.0.0.
The text was updated successfully, but these errors were encountered: