I’m having some difficulty figuring out what is wrong with the following KO setup.
http://jsfiddle.net/edsinek/m4rUz/
I’m simulating the data I’ll be getting from the server (via a hard coded data struct), hence the use of IDs throughout. I’m trying to populate the text of a span and what I’ve got is an ID that I want to use to lookup the name in the array in the VM.
The same goes for the select – I want the value to be preselected based on the ID.
Thanks in advance.
In some places you’re missing a
()when accessing observables, and in your binding strings you were missing$root.prefix for the functions.Also, the return value from inside a
$.eachcallback only serves to signal the $.each loop to stop (if you return false). You can’t return a value from inside the $.each callback and expect it to return a value from the outer function. So I changed yourmaterialByIdfunction to the commented version (but added the()for the observableArray).Here’s the updated fiddle: http://jsfiddle.net/antishok/m4rUz/2/