简体   繁体   English

如何嵌套数据绑定文本

[英]How to nest data-bind Text

Really simple request, I want to print Product() in an <h4> and Price() in a <small> that exists within the <h4> 非常简单的请求,我想在打印产品() <h4>和价格()是一个<small> 的存在<h4>

<h4 data-bind="text:Product">
    <small data-bind="text:Price"></small>
</h4>

results ignore <small> completely 结果完全忽略<small>

<h4 data-bind="html:Product() + '<small>' + Price() + '</small>'"></h4>

works, but seems like there should be a better way 工作,但似乎应该有一个更好的方法

https://jsfiddle.net/64wfpgn8/2/ https://jsfiddle.net/64wfpgn8/2/

any ideas? 有任何想法吗?

The text binding replaces all contents of the bound tag, so the small is effectively overwritten. text绑定替换绑定标记的所有内容,因此小写被有效覆盖。 You can get the effect you want with a virtual ko tag, though: 但是,您可以使用虚拟ko标记获得所需的效果:

<h4><!-- ko text:Product --><!-- /ko --><small data-bind="text:Price"></small></h4>

https://jsfiddle.net/64wfpgn8/3/ https://jsfiddle.net/64wfpgn8/3/

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

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