How do you prevent character escaping in knockout.js data binding?

This code displays a broken space escape sequence instead of the actual spaces:

<html> <head> <script src="../js/jquery.min.js"></script> <script src="../js/knockout-2.2.1.js"></script> <script> $(document).ready(function() { var modelType = function() { this.A = ko.observable('a b&nbsp;&nbsp;c'); }; var model = new modelType(); ko.applyBindings(model); }); </script> </head> <body> <p data-bind="text: A"></p> </body> </html> 

The following is displayed:

 a b&nbsp;&nbsp;c 

instead

 abc 

How to prevent this behavior?

+4
source share
2 answers

You should use html binding instead of text :

 <p data-bind="html: A"></p> 
+10
source

You can use the html binding, http://knockoutjs.com/documentation/html-binding.html :

 <p data-bind="html: A"></p> 
+1
source

Source: https://habr.com/ru/post/1499676/


All Articles