【问题标题】:Knockout: If binding callback not working淘汰赛:如果绑定回调不起作用
【发布时间】:2018-12-26 02:55:38
【问题描述】:

我有一个简单的淘汰赛组件,但我的 if 绑定不起作用,我不知道为什么。

我的模板如下:

<!-- ko if (getAlcContent($parent) > 0) -->
<div class="detail details-alc-content">
    <span class="value">
        <span data-bind="text: getAlcContent($parent)"></span>% Vol. Alc.
    </span>
</div>
<!-- /ko -->

还有我的组件:

/* ... */

getAlcContent: function(quoteItem) {
    var item = this.getItem(quoteItem.item_id);
    return item && parseFloat(item.alc_content) ? item.alc_content : undefined;
},

/* ... */

但是即使我返回了undefineddiv.detail 也会始终呈现。我也试过false0getAlcContent($parent) &gt; 0

为什么会这样? 在淘汰赛页面上,它会显示任何计算结果为 true 或 truish 的表达式,这里就是这种情况。

【问题讨论】:

    标签: knockout.js magento2 knockout-3.0 knockout-mvc


    【解决方案1】:

    这里有错别字,试试

    <!-- ko if: getAlcContent($parent) > 0 -->
    

    【讨论】:

    • 谢谢你修复它。
    猜你喜欢
    • 2013-03-01
    • 1970-01-01
    • 2014-01-10
    • 2015-12-27
    • 1970-01-01
    • 1970-01-01
    • 2012-11-14
    • 2013-12-27
    • 2012-11-08
    相关资源
    最近更新 更多