mbest / knockout-repeat

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

Bindings #2

Closed rvlietstra closed 12 years ago

rvlietstra commented 12 years ago

Hi, Thanks for all the help thus far (I'm still having issues calling jqTab but I'm working on it)

I have an issue binding an input control to my modelview:

<div data-bind="repeat: {foreach: currencies, item: '$currency', bind: 'attr: { id: $currency().Guid} '}">
  <input data-bind="value: $currency().Description" />
</div>

Which correctly fills in the Description for each currency, but when I eventually do a:

ko.toJSON({ data: self.currencies })

It doesn't return the changed data.

Thanks!

mbest commented 12 years ago

If Description is an observable, it will work. The value binding will write to things that aren't observables, but it won't write to $currency().Description since it has a parentheses in it. There's an open issue about changing that, but until then, you either have to make sure your property is an observable or that your representation doesn't include parentheses. In order to take out the parentheses, you could do this:

<div data-bind="repeat: {foreach: currencies, item: '$currency', bind: 'attr: { id: $currency().Guid}, with: $currency()'}">
  <input data-bind="value: Description" />
</div>
mbest commented 12 years ago

I had the brackets wrong in my example; now it's fixed.

rvlietstra commented 12 years ago

Thanks!