knockout.punches
knockout.punches copied to clipboard
Feature Request: foreach: items as 'item'
instead of "foreach: { data: items, as: 'item' }" binding , plz provide "foreach: items as 'item' " syntax .
thanks .
Thanks for the suggestion. Is there a precedent for this syntax?
i am just thinking a syntax like this "foreach: items as 'item' " will be cleaner . maybe "foreach: items as 'item' | filter1:arg1 | filter2 " will be even better .
like angularjs ng-repeat directive .
+1 for this feature. It is much easier to remember.
Ember's #each HandleBars helper supports something similar:
{{#each person in people}}
...
{{/each}}
I found a use for this feature in ko. Where "foreach: { data: items, as: 'item' }" is used to go through array of strings rather than objects.
Please add this feature.
I can second that this is one thing I miss from angular, {{foreach: item in items}} or {{foreach: items as 'item'}} would work for me, both are very readable syntax in my opinion. That being said, I don't mind just using ko's syntax either, so this really isn't a huge deal to me.
Personally I have switched to aurelia - it has more modern features such as templates, latest java syntax, and a very intuitive binding syntax. Its still beta, but also very functional.
@jlaustill I tried once a custom node preprocessor to have a very simple angular style of foreach. knockout.punches
has a method to add one - addNodePreprocessor
. It worked pretty cool and I also created custom attributes like ko-if
and ko-unless
. (e.g. <div ko-unless="condition"></div>
). The implementation is very simple as it's just some markup wrapping and basic parsing for foreach
.
<div ko-foreach="items as $item">
<!-- The DIV element is repeated along with the inside content -->
</div>