我希望能够在dust.js添加值是这样的:表达式和嵌套表达式在dust.js中?
this is x+1 : {{x}+1} //does not work :'(
我知道我可以用一个辅助(窘况详细)
this is x+1 : {@math key="x" method="add" operand="1" /}
做到这一点我可以住(但不开心)
但是当我想嵌套一个参数呢?
this is x+1+1 : {@math key='{@math key="x" method="add" operand="1" /}' method="add" operand="1" /} // no dice and wins ugly code prize!
this is x+1+1 : {@math key='x' method="add" operand="1"} {@math key="selectKey" method="add" operand="1" /} {/math} //still no dice - btw selectKey is an output variable for the @math helper
可以做到这一点吗?我很想尝试在核心库中打补丁,因为这太令人讨厌了。
还有什么其他方法可以做到这一点?创建临时变量(即{xplus1})?我目前的解决方案是将任何/所有逻辑移动到助手 - 我正在写很多助手。
更新:
我写了可以创建范围的变量帮手。这似乎是一个干净的方式来做到这一点。
{@eval xplus1="{x} + 1"}
... scope where x = x+1
this is x+1 : {xplus1}
{/eval}
现在它使用JavaScript的eval,但我使用一个JS数学LIB像JavaScript Expression Evaluator或
有趣的是,我有完全一样的问题。你有公开的eval助手的源代码吗? – quentinadam
嗨goldmine - 我的实现实际上是在GWT中 - 但让我看看我是否可以复制它并转换为JS –