Fiddle: http://jsfiddle.net/amitava82/dawkn/6/
The input elements will be generated dynamically based on json data received from server. Here I’m using text fields but it could be select, radio etc and n number of them. Now, I’m confused how do I get values from these input elements and also associate them with respective models item so that I can send them to server. Appreciate any help. Thanks!
You need to define custom model for each data. For example:
I’ve added the
forso you can do this:Now when you create the
viewModelyou can do this:In your template you can use this:
and finally in
savemethod:function
ko.toJStransformsko.observablesto its values. When you havenewValuesthen you can stringify them withJSONfor example and send them to the server.That’s more or less how I would do that. Feel free to ask additional questions in comments below.