Pregunta

I'm trying to understand native knockoutjs template binding, especially foreach binding.

Just wondering how to access current item using native bidning? With jQuery.tmpl it is possible using something like $item / $data. How to do the same using native template binding when data source is the arrays of primitives so each item has no named fields? Here is the JSFiddle with two examples, the first - using native binding where data source is array of custom objects, second one - binding to an array of strings. I'm unable get it working, looks like I'm missing something obvious?

Basically I'm trying to understand native bindings and be able refactor following example using native binding: JSFiddle: Comma separated list of checked items so I would be able keep an observable variable which represnts a comma separated list of checked items.

¿Fue útil?

Solución

You can use $data to access the raw value like: http://jsfiddle.net/rniemeyer/M73S8/3/.

Here is the other fiddle updated: http://jsfiddle.net/rniemeyer/EGAH9/8/. Not sure the exact functionality that you want to support in it.

Otros consejos

I am not sure if this is already answered from the amazing Niemeyer (thanks for all of your help in the Knockout Community!), but I made a jsFiddle to show storing the actual Person objects Selected in an observable array.

I am not sure if that is what you are trying to do, but maybe someone else is researching this looking on how to do this exact thing: bind the actual objects into an observable array, not just the ids (although, i added that too to remind me).

Example of a Checkbox List Selected Object Binding: http://jsfiddle.net/cjgaudin/Dp7Br/

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top