I have a simple foreach:
-
Use the $data
prefix, KO can parse it
Sample:
http://jsfiddle.net/baryon/NsuL7/1/
讨论(0)
-
So, there are a few options that you have:
KO will have an issue when you try to bind against undefined properties, unless they are off of an object. So, you can prefix your various bindings with $data.
and KO will be able to parse your bindings. Sample: http://jsfiddle.net/rniemeyer/dLCL8/ If you know that several properties will always be together, then you could use a with
or if
statement around those options.
A different take on handling "undefined" properties is to create a binding that populates these properties when they are missing. Look at this answer. It would be similar, but potentially with the 'text' binding. Sample: http://jsfiddle.net/rniemeyer/dLCL8/4/
讨论(0)