knockout binding to array element without template works only one-way
Can someone please please help me better understand binding t开发者_高级运维o observable array elements without using templates?
I have a table that contains more than the data that I am attempting to present from the array. My array is fixed size, so to avoid the challenges of layout, I wanted to bind input boxes directly to array elements. I can get it to bind one-way to the view, but updates are not being recognized. Here is my sample: jsfiddle
I have unsuccessfully tried to make each element observable, but I get the same result.
The syntax to access the array item is causing Knockout to not create a callback to update the value for a one-way binding when it changes (it thinks it is an expression and not writeable). For example, it would work properly if you did:
viewModel.test = viewModel.recipients()[0];
and then did:
<input data-bind="value: test.emailAddress"/>
So, your scenario illustrates that this is an issue in Knockout. This would also work properly in the template binding or if you don't want to use the template binding, then it would also work properly to make emailAddress
an observable.
It would look like: http://jsfiddle.net/rniemeyer/3JmbA/2/
So, you would make emailAddress an observable in your constructor and your alert would need to access the observable value as a function.
精彩评论