Search code examples
bindingmvvmknockout.jstemplatebindingknockout-2.0

Knockoutjs native template binding and simple array of strings


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.


Solution

  • 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.