Sunday, 29 September 2013

knockout "with" binding: each property to multiple controls

knockout "with" binding: each property to multiple controls

Within "with" binding div, I tried to bind 5 properties of a model to 2
different types of controls, namely textbox and label. However, only the
first property on the list is bound to two controls, the rest are only
bound to textbox:
<div data-bind="with: Object">
<input type= "text" data-bind="value: property1" /> <br />
<input type= "text" data-bind="value: property2" /> <br />
<input type= "text" data-bind="value: property3" /> <br />
<input type= "text" data-bind="value: property4" /> <br />
<input type= "text" data-bind="value: property5" /> <br />
<label data-bind="value: property1" /> <br />
<label data-bind="value: property2" /> <br />
<label data-bind="value: property3" /> <br />
<label data-bind="value: property4" /> <br />
<label data-bind="value: property5" /> <br />
</div>
Object is populated dynamically, meaning its properties are assigned
dynamically. In my view model, I have Object = ko.observable() . And once
user clicked some button, I have Object(createModel1()) executed, where
createModel1 returns a new Model1. Model1 has properties defined as
ko.observable.
I don't know whether this is not supposed to work or am I doing something
else wrong (barking at the wrong tree) Please help! Thank you!!!

No comments:

Post a Comment