Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

This code displays the non-breaking 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>

It displays the following:

a b&nbsp;&nbsp;c

instead of

a b  c

How do I prevent this behavior?

like image 528
Charles Lambert Avatar asked Dec 16 '22 07:12

Charles Lambert


2 Answers

You should use html binding instead of text:

<p data-bind="html: A"></p>
like image 61
Artem Vyshniakov Avatar answered Mar 15 '23 22:03

Artem Vyshniakov


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

<p data-bind="html: A"></p>
like image 34
lagerone Avatar answered Mar 15 '23 23:03

lagerone