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 objects with #each #40
Comments
The behavior of If the data is an array, it iterates for each item - which becomes the current dataItem for that rendered template (view) - and concatenates the result. But if dataExpression returns a single object, then it renders just once, with that object as current data item. If you don't pass any data at all, as in I am considering changing the name of the tag from each to {{for}} to make less surprising that it does not iterate when you pass it a singleton. It is not a common scenario to render the same template against each of the properties of an object. Usually you know, statically, the properties of the object, and can do
If you want to apply the same template to each property, as an iteration over all the properties, you can provide a helper function to return the array, rather than add a new array to your data, as in See also this comment on my blog |
See also #49 |
My apologies for necro-posting, but I wanted to provide an example of why someone might want to iterate through the properties of an object. In a nutshell, for the purposes of data-linking, an array/collection does not allow (or very easily allow) for changing just one property of one entry. Take this data:
And I render it like so: I could then update a particular person like I think - I haven't tested this, but looking through the source, I'm guessing this is how it works By only being able to iterate over arrays, I either need to
Is there another way to approach this? |
I agree there are scenarios where this is useful. I hope to be able to look into supporting it... |
Can we reopen this issue then please? It's definitely necessary, and the original poster closed the ticket for some reason. |
That looks perfect. Thanks! |
Any chance of reopening this issue? It took me a while to figure out hashes are not supported by {{for}}. Cool that you can do it via custom helpers, but this seems rather fundamental. |
OK, makes sense. Reopening as a feature request for built-in support. |
This feature is now supported, using the new
|
Currently #each only works if you have an array, so i am having to do a costly conversion:
http://jsfiddle.net/pixelhobo/E9dUm/
It would be much better you went over the key/value pairs of an object, something like this:
http://jsfiddle.net/pixelhobo/cfEnt/
The text was updated successfully, but these errors were encountered: