HTML实体与淘汰赛 [英] HTML Entities with Knockout

查看:130
本文介绍了HTML实体与淘汰赛的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在绑定到viewModel中的变量的字段中输出HTML实体?我想显示一个HTML实体,例如< (& larr; )绑定到HTML中的 span >的字段中。不幸的是,HTML被转义了,所以浏览器显示&而不是符号。

How can I output HTML Entities in fields that are bound to a variable in the viewModel? I would like to display an HTML Entity like ← (&larr;) in a field bound to a span in the HTML. Unfortunately, the HTML is escaped, so the browser displays &larr; instead of the symbol.

小提琴例如:
http://jsfiddle.net/nwinkler/KES2j/

JavaScript:

JavaScript:

var data = { value : '&larr;'};

var viewModel = {
    field: ko.mapping.fromJS(data)
};

ko.applyBindings(viewModel);

HTML:

HTML:

<p>HTML: &larr;</p>
<p>Knockout: <span data-bind='text: field.value'></span></p>


推荐答案

您可以使用 html 绑定这样的东西。它看起来像:

You can use the html binding for something like this one. It would look like:

<p>Knockout: <span data-bind='html: field.value'></span></p>

示例: http://jsfiddle.net/rniemeyer/KES2j/1/

这篇关于HTML实体与淘汰赛的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆