You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the result of the log would be ["a",true], 0 while I'd expect this to be true and @key to be "a" like it is when you call each on an Object.
The solution would be to on Line 36 of each.js call context.get(field) instead of context[field]. Of course it'd have to know for sure it was a Map at that point.
So it could be resolved either by adding a property to execIteration of isMap (or perhaps a more generic solution with calling a function on context) to determine whether it should use the index signature or call .get or some other function.
Or alternatively; if context is a Map, transform it into an Object Record instead.
I have already resolved this locally, but thought I'd share this here in case someone wants to pick this up and add it to Handlebars itself.
I resolved this by overwriting the each helper, checking if the context is a map, and if so using context.get(field) instead of context[field]. If it isn't a map, parse it using the original Handlebars each helper.
The text was updated successfully, but these errors were encountered:
Due to the way that the Map handler of the each function is currently done the value is returned as a multi dimensional array.
handlebars.js/lib/handlebars/helpers/each.js
Lines 47 to 51 in 25c696b
During the
execIteration
function the Map value getter is now called as such:handlebars.js/lib/handlebars/helpers/each.js
Line 36 in 25c696b
However a
Map
doesn't support index signatures, thuscontext[field] === undefined
and instead needs to be called usingMap#get
.In the case of the following handlebars code w/ appropriate map:
the result of the log would be
["a",true], 0
while I'd expectthis
to betrue
and@key
to be"a"
like it is when you call each on an Object.The solution would be to on Line 36 of each.js call
context.get(field)
instead ofcontext[field]
. Of course it'd have to know for sure it was a Map at that point.So it could be resolved either by adding a property to
execIteration
ofisMap
(or perhaps a more generic solution with calling a function on context) to determine whether it should use the index signature or call .get or some other function.Or alternatively; if context is a Map, transform it into an Object Record instead.
I have already resolved this locally, but thought I'd share this here in case someone wants to pick this up and add it to Handlebars itself.
I resolved this by overwriting the each helper, checking if the
context
is a map, and if so usingcontext.get(field)
instead ofcontext[field]
. If it isn't a map, parse it using the original Handlebars each helper.The text was updated successfully, but these errors were encountered: