mbest / knockout-repeat

REPEAT binding for Knockout
http://mbest.github.io/knockout-repeat/
131 stars 18 forks source link

binding as virtual element #10

Closed kirtapatrik closed 11 years ago

kirtapatrik commented 11 years ago

How is it possible, to use the binding as a virtual element?

mbest commented 11 years ago

It's not possible currently. What's your use-case?

kirtapatrik commented 11 years ago

I generate n <td> depends on a variable count. Actually i create them with a dummy array with length n and a virtual foreach. But this is not really fast.

mbest commented 11 years ago

So why can't you use an element for the repeat?

kirtapatrik commented 11 years ago

Because the repetition is in the middle of the table. <tr><td>fix</td><td>fix</td> repetition--> <td>n</td> <td>fix</td></tr>

mbest commented 11 years ago

You should be able to do this: <tr><td>fix</td><td>fix</td><td data-bind="repeat: n">n</td><td>fix</td></tr>

kirtapatrik commented 11 years ago

Yes of course, great, my fault. thx, for your support

mbest commented 11 years ago

You're welcome.

skilesare commented 10 years ago

I ran into this same issue but I also need to set the id of the td. I tried:

<td  data-bind="repeat:{foreach:$root.titlePlant.displayDefinition().sourcesToProcess[$data.SearchableIndexDisplayFieldID],item: '$field'},attr:{'class':'MemberField Field' + $field().SearchableIndexFieldID + ' FieldSource' + $field().SearchableIndexDisplayFieldSourceID}">

I got $field doesn't exist. With a virtual binding I could get a ref to each item and set the id.

mbest commented 10 years ago

repeat should generally be the only binding in data-bind. The bindings for each repeated item should be in data-repeat-bind.

<td 
  data-bind="repeat:{foreach:$root.titlePlant.displayDefinition().sourcesToProcess[$data.SearchableIndexDisplayFieldID], item:'$field'}" 
  data-repeat-bind="attr:{'class':'MemberField Field' + $field().SearchableIndexFieldID + ' FieldSource' + $field().SearchableIndexDisplayFieldSourceID}">
skilesare commented 10 years ago

Ahh...ok....makes sense