【发布时间】:2016-03-19 05:38:20
【问题描述】:
我正在使用敲除模板将可观察数组绑定到视图。我有一个对象数组,但我只想显示满足特定条件的对象。无论如何使用淘汰模板绑定来做到这一点?我目前正在使用提出的第二种解决方案(可行),因为第一种会导致错误,但我觉得可能有更简洁的方法来做到这一点。
期望的解决方案(产品未定义的错误):
<div class="productItem" data-bind="template: { name: 'product-template',foreach:'history', as:'product', if: product.Count === 1}"></div>
我的解决方法:
<!-- ko foreach: { data: history, as: 'product' } -->
<div class="productItem" data-bind="template: { name: 'product-template', if: product.Count === 1}"></div>
<!-- /ko -->
【问题讨论】:
-
您至少应该将
"history"的双引号替换为单引号。此外,我确定您不能将foreach和if组合在一个绑定中。