I have a ko.observable property of an object called "totalLength". While using application I would like to physically amend new value to this property. How can I do that?
I can preview the value of the demanded property by displaying:
alert(feature.totalLength());
so I know that it is the one. But when I assign a new value to it:
feature.totalLength() = 10;
I get an error:
ReferenceError: invalid assignment left-hand side
Why?
To write a new value to the observable, call the observable and pass the new value as a parameter. For example, calling myViewModel. personName('Mary') will change the name value to 'Mary' . To write values to multiple observable properties on a model object, you can use chaining syntax.
Syntax. You just need to declare ViewModel property with function ko. observable() to make it Observable.
unwrap method is used to read it), the current viewModel and bindingContext. Whenever the passed value changes the binding will print updated information to console. This binding cannot be used with virtual elements (in html comments), only on real elements, since ko.
ko.observable
is a function so you need to set the value like this feature.totalLength(10)
.
You can change value of observable like this:
feature.totalLength(10)
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