如何将数据绑定到knockout js中的特定位置?

时间:2014-06-24 07:56:36

标签: javascript knockout.js

如何使用knockout将“ActiveSellers”计数与“描述”的值绑定?

<div class="detailProductPrice">
"Description"
<a class="compare comparea" data-bind="attr: {'href': '/product/'+ FolderName}"   target="_top">COMPARE PRICE</a> 
from "ActiveSellers" sellers
</div>

“描述”部分是html。 “ActiveSellers”是一个数字。

2 个答案:

答案 0 :(得分:0)

您可以添加空的span元素:

<div class="detailProductPrice">
<span data-bind="html: Description"></span>
<a class="compare comparea" data-bind="attr: {'href': '/product/'+ FolderName}"       target="_top">COMPARE PRICE</a> 
<span data-bind="text: ActiveSellers"></span>
</div>

或使用没有容器元素的KO绑定

<div class="detailProductPrice">
<!--ko html: Description--><!--/ko-->
<a class="compare comparea" data-bind="attr: {'href': '/product/'+ FolderName}"       target="_top">COMPARE PRICE</a> 
<!--ko text: ActiveSellers--><!--/ko-->
</div>

答案 1 :(得分:0)

尝试使用containerless element

<div class="detailProductPrice">
    <!--ko html: Description--><!--/ko-->
    <a class="compare comparea" 
       data-bind="attr: {'href': '/product/'+ FolderName}"
       target="_top">COMPARE PRICE</a> 
    from <!--ko text: ActiveSellers--><!--/ko--> sellers
</div>