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
Iterate over object key/value pairs? #457
Comments
Hi @chlab! Instead of passing your data directly to the renderer, you should format it into a http://stackoverflow.com/questions/9058774/handlebars-mustache-is-there-a-built-in-way-to-loop-through-the-properties-of Let us know if it's still not clear. Cheers! |
Thanks @dasilvacontin. |
@chlab This is a fundamental principle of Mustache. All logic should be extracted into a view, which is not the same as a template. In this case, it seems more awkward because it's just a little bit of logic, but that's a slippery slope that Mustache doesn't even let you go down :) |
Fair enough. Thanks for the explanation! |
The fundamental principle that was originally referred to, makes Mustache too opinionated, I do not always want to arrange a separate conversion phase to make Mustache happy... |
Is allowing iteration over a simple object really introducing logic into a mustache view? My argument would be no. I am a fan of the logic-less principle, but we can already iterate arrays, I agree with the OP that this is unnecessarily awkward. Consider the following example: I'd like my data to be:
But it has to be:
To render:
|
Hi guys, How can I iterate an anonymous list? I tried using {{#.}} and {{/.}} but thats not working. Thanks |
To iterate an anonymous list
|
There are something in this issue that is official? How to do real use of anonymous list of objects with key-value pairs? Please show a real example using the suggested object, PS: @prashantcs8 your example is real? not working. |
@chlab we are in 2018... There are no option in Mustache to use anonymous references? |
@baseten , about yor "But it has to be" above, that is the problem, is ugly to enforce data-structure convertions... It is not an elegant solution, but I am using function objs2list(p) {
r = [];
for (var key in p) if (p.hasOwnProperty(key)) {
r.push({"@key":key,"@val":p[key]});
}
return r;
} exist? |
Is it possible to iterate over the key/value pairs of an object?
Consider this example:
Equivalent handlebar.js code:
I did not find a way to do it with mustache.js
Thanks.
The text was updated successfully, but these errors were encountered: