I would like to remove/clear a field of its bindings.
self.Selected = ko.observable();
"Selected": {
"ID": 5,
"Name": "22",
"Active": true,
"Temp": "2013-01-28T18:14:48.340Z"
}
self.Selected.remove() --- > error: has no method 'remove'
self.Selected.removeAll(); --> Cannot call method 'removeAll' of undefined
self.Selected.cleanNode()--- > error: has no method 'cleanNode'
http://jsfiddle.net/yvTFN/24/ : so you can see a working example
After you EDIT a name, the self.update = function will do work, then should clear the property Selected, otherwise, if you click update again (no value), the value will update with empty string.
To clear an observableArray you can set the value equal to an empty array.
Knockout. js defines an important role when we want to detect and respond to changes on one object, we uses the observable. An observable is useful in various scenarios where we are displaying or editing multiple values and require repeated sections of the UI to appear and disappear as items are inserted and deleted.
To read the observable's current value, just call the observable with no parameters. In this example, myViewModel. personName() will return 'Bob' , and myViewModel. personAge() will return 123 .
unwrapObservable(item) Looking at the code, that call basically checks to see if item is an observable. If it is, return the value(), if it's not, just return the value.
Just set the value of Selected
to null
:
self.Selected(null);
Edit: Your jsfiddle is using ko.removeNode
which does not what you want.
For a working version see: http://jsfiddle.net/yvTFN/26/
self.Selected.clearBindings = function __clearSelection__() {
self.Selected = new ko.observable(self.Selected());
self.Selected.clearBindings = __clearSelection__;
}
This approach may do what you need, depending on what it is you really need... There are some caveats
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