【问题标题】:How can I add expression to if clause condition in trimpath?如何将表达式添加到修剪路径中的 if 子句条件?
【发布时间】:2012-09-19 17:25:20
【问题描述】:

我正在使用trimpath library来绘制动态页面

我尝试在 if 子句中添加表达式

{for item in itemsObj}
 {if item_index % 4 == 3 && peopleObj.length != item_index + 1 }
     <div class="search-result-row" style="border-bottom:1px solid #dadada;">
 {/if}
{/for}

但值“item_index + 1”未计算为数学表达式,该值的结果是绑定字符串 例如 如果 item_index = 3 那么表达式的结果是 = 31

你能帮我解决这个问题吗?

【问题讨论】:

  • 你试过(item_index + 1)吗?
  • 是的,我尝试这个仍然将结果作为字符串绑定

标签: javascript open-source web-deployment-project


【解决方案1】:

免责声明:我没有使用此库的经验。

根据the documentation:

testExpr 是任何有效的 JavaScript 表达式,但没有右大括号 字符。

这意味着你应该能够做到这一点:

{if item_index % 4 == 3 && peopleObj.length != (parseInt(item_index, 10) + 1) }

【讨论】:

  • @KhadijahJShtayat 如果此答案对您有所帮助,并且您认为它会帮助未来有类似问题的访问者,您应该接受答案(单击绿色复选标记)。
猜你喜欢
  • 2021-02-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-17
相关资源
最近更新 更多