Bugfix: <!-- ko text: valueAccessor --> failed

https://knockoutjs.com/documentation/text-binding.html#note-3-using-text-without-a-container-element
This commit is contained in:
djmaze 2021-08-12 12:54:42 +02:00
parent 467b4a7913
commit 74f74163c6
3 changed files with 31 additions and 21 deletions

View file

@ -4,7 +4,12 @@ ko.bindingHandlers['text'] = {
// It should also make things faster, as we no longer have to consider whether the text node might be bindable.
return { 'controlsDescendantBindings': true };
},
'update': (element, valueAccessor) =>
ko.utils.setTextContent(element, valueAccessor())
'update': (element, valueAccessor) => {
if (8 === element.nodeType) {
element.text || element.after(element.text = document.createTextNode(''));
element = element.text;
}
ko.utils.setTextContent(element, valueAccessor());
}
};
ko.virtualElements.allowedBindings['text'] = true;