Re: How can I pass $data to a ko.computed function in a foreach loop binding?

4,070 views
Skip to first unread message

Casey Corcoran

unread,
May 16, 2012, 4:48:44 PM5/16/12
to knock...@googlegroups.com
Like this?  http://jsfiddle.net/snaptopixel/pF9q6/ 

You're invoking the function on each iteration, all you need to do is format the string and return it...

Hope that helps,
Casey

On Wed, May 16, 2012 at 3:55 PM, Jeffer <jf.stg...@gmail.com> wrote:
I need to perform something equivalent to this:

<ul data-bind="foreach: tags">
  <li data-bind="text: $parent.formatTagText($data)"></li>
</ul>

Then in the model I'd have a formatTagText function that formats how the tag fields should be outputted as text.
Using ko.computed doesn't seem to permit passing parameters (the current item being iterated over). 
Basically I'd need to invoke a function that could take the current iterated item the same way it's possible for the click binding but for the text binding...

Any suggestions on ways to achieve this?

Thanks!

haree...@gmail.com

unread,
Jul 25, 2012, 1:28:05 AM7/25/12
to knock...@googlegroups.com
this is very help full Casey, You saved my day !
Reply all
Reply to author
Forward
0 new messages