Knockout.js carraige 在段落文本中返回 [英] Knockout.js carraige return in paragraph text

查看:23
本文介绍了Knockout.js carraige 在段落文本中返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用knockout.js,如何在绑定到段落<p> 元素的文本属性的文本中包含回车符.

Using knockout.js, how do I include a carriage return in the text that is bound to the text attribute of a paragraph <p> element.

在我的 ViewModel 中,我生成了一个文本字符串,该字符串绑定到视图中的 <p>.我想在浏览器显示的带有换行符的字符串中包含回车符.

In my ViewModel I generated a string of text that is bound to the <p> in the View. I want to include carriage returns in the string which the browser displays with the line breaks.

在字符串中包含 <br/>Environment.NewLine 似乎不起作用.

Including <br /> or Environment.NewLine in the string does not seem to work.

推荐答案

您可以使用 html 绑定.

JS:

function AppViewModel() {
    this.firstName = "Bert<br>Test";
    this.lastName = "Bertington";
}

// Activates knockout.js
ko.applyBindings(new AppViewModel());

查看:

<p>First name: <strong data-bind="html: firstName">todo</strong></p>
<p>Last name: <strong>todo</strong></p>

看小提琴

这篇关于Knockout.js carraige 在段落文本中返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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