1

I'd like to join $index and $data in text binding:

<ul data-bind='foreach: myItems'>
    <li data-bind="text: $index() + ': ' + $data()"></li>
</ul>

but the syntax above is not working. Is such scenario not supported in KO? Have I to write some helper function or computed observable into my model?

4

1 に答える 1

2

Unless you have functions inside the myItems array your $data won't be normally a function so you don't need the ():

As your exception also tells this:

TypeError: $data is not a function;

So the following code should work:

<ul data-bind='foreach: myItems'>
    <li data-bind="text: $index() + ': ' + $data"></li>
</ul>
于 2013-03-12T14:45:09.633 に答える