【问题标题】:Divide two values in bigcommerce在 bigcommerce 中划分两个值
【发布时间】:2020-08-06 00:38:05
【问题描述】:

有人知道两个值是否可以相除吗?

例如:

产品价格/单价=想要的结果

产品价格:

      {{price.without_tax.formatted}}

单价过滤器

      {{#filter custom_fields 'Units per case' property='name'}}
      <p>{{ value}}</p>
      {{/filter}}

如果我要使用类似的东西:

    {{#filter custom_fields 'Units per case' property='name'}}
           <p>{{toFixed price.without_tax.formatted divide value}}</p>
     {{/filter}} 

我得到一个 0。如果我不包括 toFixed 那么什么都不会出现。不知道如何进行。请帮忙。

(我知道这是一些疯狂的代码,但我不知道更好。)

【问题讨论】:

    标签: handlebars.js bigcommerce


    【解决方案1】:

    我看到了许多问题。试试这个:

    {{#filter custom_fields 'Units per case' property='name'}}
           <p>{{toFixed (divide ../price.without_tax.value value) 2}}</p>
    {{/filter}} 
    
    • 使用price.without_tax.value 而不是price.without_tax.formatted,因此它返回一个数字而不是字符串。
    • ../ 添加到价格对象,因为它嵌套在{{filter}} 中。
    • 除法语法为{{divide a b}}
    • 我在{{toFixed}} 中添加了一个参数“2”,因此它显示了带2 个小数位的结果。

    【讨论】:

    • 非常感谢!我把这搞砸了,肯定的!感谢您的帮助,感谢您解释了一些事情,因此我可以阅读此内容。
    猜你喜欢
    • 1970-01-01
    • 2017-04-08
    • 2015-06-12
    • 1970-01-01
    • 1970-01-01
    • 2021-10-27
    • 1970-01-01
    • 2017-05-18
    • 2019-09-07
    相关资源
    最近更新 更多