我如何将数据绑定到knockoutjs中的特定位置

How can I bind data to a specifc location in knockoutjs?

本文关键字:定位 位置 knockoutjs 数据绑定      更新时间:2023-09-26

如何将"ActiveSellers"计数与使用knockout的"Description"值绑定?

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

"Description"部分是html。"ActiveSellers"是一个数字

尝试使用无容器元素:

<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>

您可以添加一个空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>