javascript - Knockout JS how to bind observable of object html bind -
Let me cssstl one To clarify the obsebable need to see what holds the object set by me, we go with a small part of the code:
View Module:
Define ('vm.test', ['ko', 'model'], function ko, model) {var myObject = ko.observable (new model.MyModel ()), someFunction = function () {// here some The code that is going to get the object data myObject.property1 = data.test, myObject.property2 = data. test2; myObject.property3 = data.test3;}; Return {myObject: myObject, someFunction: someFunction};}); Model:
Define ('model.mymodel', ['ko'], function (to) {var MyModel = function} Var itself = this; self.property1 = ko.observable (); self.property2 = ko.observable (); self.property3 = ko.observable (); self.isNullo = false; auto return;}; MyModel.Nullo = New MyModel (). Property 1 (''). Property 2 (''). Property 3 (''); Mymodel. Nullo.isNullo = true; Return MyModel;}); And what I want to achieve is to force each object to separate my object, we say, in HTML I have tried to do this in many ways, But unfortunately without any success. Does anyone know how to tie this type of object to isolate spines? I have already tried and did not work for me:
approach 1:
& lt; div data-bind = "with: myObject" & gt; & Lt; Span data-bound = "text: $ data.property1" & gt; & Lt; / Span & gt; & Lt; Span data-bound = "text: $ data. Property2" & gt; & Lt; / Span & gt; & Lt; Span data-bind = "text: $ data.property3" & gt; & Lt; / Span & gt; & Lt; / Div & gt; approach 2:
& lt; Duration Data-Tie = "text: myObject.property1" & gt; & Lt; / Span & gt; approach 3:
& lt; Duration Data-Tie = "text: MyObject () property1" & gt; & Lt; / Span & gt; And none of those functions work binding with visual models, as well as the entire framework, because I use other properties (simple overview or observation) without the view of use in vm Trouble for any problem. What's more, if I write consolation to myObject's content from within the visual model, then it is filled with the values that I wanted, however, the value is not assigned to see.
Maybe changing it:
myObject = ko.observable (new Model.MyModel ()), For this:
myObject = new model.MyModel (), < P> Edit: Demo
Edit 2: Please note that you can not update your observations like this:
myObject .property1 = data.test; But instead, you call the function:
myObject.property1 (data.test);
Comments
Post a Comment