Hi I'm very new to knockout js
.
Please anyone tell me the difference between
{ id: 1, Name: "Nokia", Price: 3000 }
{ id: ko.observable(1), Name: ko.observable("Nokia"), Price: ko.observable(3000)
Thanks
KO is that it updates your UI automatically when the view model changes. How can KO know when parts of your view model change? Answer: you need to declare your model properties as observables, because these are special JavaScript objects that can notify subscribers about changes, and can automatically detect dependencies.
It's pretty simple. Just refer the help documentation for knockout.js
http://knockoutjs.com/documentation/observables.html
Hope it helped
The documentation and its tutorial are indeed great.
Briefly: ko.observable
returns a getter/setter function. Your first object is just plain values.
In the first case you can do obj.Price = obj.Price + 1000
.
In the second you should do obj.Price(obj.Price() + 1000)
.
The benefits of the function approach is that it enables automatic change tracking.
If this is not clear enough, please look at KO's documentation, it's very good.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With