我只是想知道,有什么方法可以实现以下目的.
<button class="{{unless publishable "button-disabled"}}" {{if publishable (action "publish")}}>Publish</button>
Run Code Online (Sandbox Code Playgroud)
当然,它可以用动作方法完成.我认为如果可以在模板中完成,它可以使代码更干燥.
注意:
disabled属性来实现这一点.在我原来的作品中,它实际上是一个<a/>没有的作品disabled.我需要将它作为<a/>css用途的标记.可以{{mut}}与{{action}}帮助者结合使用:
<button {{action (if publishable 'publish' (action (mut undefProp)))}}>Publish</button>
Run Code Online (Sandbox Code Playgroud)
您可以mut在此博客文章中阅读有关此特定用例(转换为函数)的更多信息.
说明:
我们使用动作助手和动作,我们将根据if条件计算传递给助手的动作.
如果condition的计算结果为true,则返回'publish'简单的动作名称.
如果condition的计算结果为false,那么我们通过的动作什么都不做 - 我们使用类似的解决方法:(action (mut undefProp)).
| 归档时间: |
|
| 查看次数: |
493 次 |
| 最近记录: |