简体   繁体   English

Knockout.js绑定到复杂的html对象

[英]Knockoutjs binding to complex html object

I have a bootstrap dropdown, with badges in the items. 我有一个bootstrap下拉菜单,其中有徽章。 I think this is not so complex, but I can't do this: 我认为这并不复杂,但是我不能这样做:

<ul class="dropdown-menu" role="menu" data-bind="foreach: events">
    <li><a href="#" data-bind="text: $data.name"><span class=" badge pull-right" data-bind="text: $data.value">NUMBER FROM MODEL TOO</span></a></li>
</ul>

My problem, that binding is working li items are generated, but the li's innerHtml's have just the text, not the text + span with binded number. 我的问题是,绑定正在生成有效的li项,但是li的innerHtml只是文本,而不是带有绑定号的文本+ span。

How can I do this? 我怎样才能做到这一点?

If you use the text binding on the a tag, its entire content will be replaced by $data.name. 如果在标签上使用文本绑定,则其全部内容将被$ data.name替换。 To also display the value along with the name, you can do this: 要同时显示值和名称,可以执行以下操作:

<ul class="dropdown-menu" role="menu" data-bind="foreach: events">
    <li><a href="#"><span data-bind="text: $data.name"></span><span class=" badge pull-right" data-bind="text: $data.value">NUMBER FROM MODEL TOO</span></a></li>
</ul>

Fiddle: http://jsfiddle.net/JUEth/2/ 小提琴: http : //jsfiddle.net/JUEth/2/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM