What I want to do is this:
<input data-bind="value: Adult.FirstName, visible: editable" />
<span data-bind="text: Adult.FirstName, visible: !editable"></span>
viewModel = kendo.observable({
editable: false
});
But I get the error:
Uncaught SyntaxError: Unexpected token !
The only ways I’ve been able to figure out how to do it are:
<input data-bind="value: Adult.FirstName, visible: editable" />
<span data-bind="text: Adult.FirstName, visible: not('editable')"></span>
viewModel = kendo.observable({
editable: false,
not: function(value) { return !this.get(value);},
});
and:
<input data-bind="value: Adult.FirstName, visible: editable" />
<span data-bind="text: Adult.FirstName, visible: notEditable"></span>
viewModel = kendo.observable({
editable: false,
notEditable: function() { return !this.get("editable");},
});
But I would rather just keep track of the one variable with no extra functions.
You can just use the invisible data bind.
http://docs.telerik.com/kendo-ui/getting-started/framework/mvvm/bindings/invisible
Or you can monitor the change event of your viewModel, check for editable changing, and change a second viewModel property to the opposite value. Then you'd have two properties, but really only have to manage one of them.
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