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
Arrays converted to strings #146
Comments
Yes, this is by design. Any key that matches in the data object will get coerced into a string if it is not "falsy". In the case of arrays, JavaScript coerces them into strings in the format If you want anything different, you need to write the template manually. Something like:
Hope that helps. |
this comes pretty close. Using [{{#Optionen}}"{{.}}", {{/Optionen}}] I get ["x", "y", "z", ] |
issue closed |
Sorry, not sure what you are trying to do. Not sure what "saving" means, but to eliminate the last comma in Mustache, I think the only way to do it is to introduce a flag variable by pre-iterating the list in JavaScript, which quickly becomes more trouble than its worth. I think the helpers functionality that @janl is building out might make this easier to solve in Mustache itself, but I'm not sure since I'm not too familiar with it. Alternatively, look at JSON.stringify and JSON.parse (built in to the browser) which may help out in de/serializing arrays into the format you are expecting. |
I found the solution: .split(", ") did it! 2011/12/12 Sahab Yazdani <
|
I have this array:
"Optionen": [
"x",
"y",
"z"
]
When I call "{{Optionen}}" this is returned: "x,y,z"
But I need to get ["x", "y", "z"]
Is this a bug or am I missing something?
The text was updated successfully, but these errors were encountered: