I created this custom binding handler:
ko.bindingHandlers.line = {
update: function (element, valueAccessor, allBindings) {
// First get the latest data that we're bound to
var value = valueAccessor();
// Next, whether or not the supplied model property is observable, get its current value
var valueUnwrapped = ko.unwrap(value);
// Now manipulate the DOM element
if (valueUnwrapped) {
$(element).after('<br />'); // Make the element invisible
}
return ko.bindingHandlers.text.update(element, function () {
return valueUnwrapped;
})
}
};
I'm wondering about the part where I do ko.bindingHandlers.text.update. Is there a better way to solve this?
Is it the only way to update the DOM with ko.bindingHandler.text.update, or is there any more straightforward way to do it?