knockout viewmodel property undefined

后端 未结 2 1086
遇见更好的自我
遇见更好的自我 2020-12-08 04:24

I have a simple foreach:

相关标签:
2条回答
  • 2020-12-08 05:16

    Use the $data prefix, KO can parse it

    Sample: http://jsfiddle.net/baryon/NsuL7/1/

    0 讨论(0)
  • 2020-12-08 05:24

    So, there are a few options that you have:

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

    2. 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 讨论(0)
提交回复
热议问题