Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
64
rated 0 times [  66] [ 2]  / answers: 1 / hits: 22252  / 13 Years ago, sun, january 15, 2012, 12:00:00

How can I control the foreach to ignore certain elements by using a comparison?



What I want for example is something like this:



<div data-bind=foreach: entry where (entry.number > 10)>


So what I would want it to do is loop through entry's but only execute when that current entry has a number value of more than 10.



Is this possible to do?


More From » knockout.js

 Answers
5

Currently that's not possible with knockout.js, but it's an interesting feature. You should file a bug report/contact the author to consider it for a future version.



Way 1:



<div data-bind=foreach: entry>
<div data-bind=if: entry.number > 10></div>
</div>


Way 2:

Write a custom filter method that gives you an array of elements that match your conditions and use this in your foreach.


[#88010] Friday, January 13, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jarrettw

Total Points: 300
Total Questions: 98
Total Answers: 103

Location: Saudi Arabia
Member since Mon, Sep 5, 2022
2 Years ago
;