- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用"dustjs-helpers": "1.6.0"
, 与 "dustjs-linkedin": "^2.6.0"
。
在我的模板中,我需要检查一个 OR 条件,例如
if( cherry === true || berry === true)
path/to/template1/
else
path/to/template2/
如何使用 Dust 助手完成此操作?
最佳答案
因为您要测试两个不同的变量,所以您需要两个不同的真值测试。
您可以将此逻辑放入您的模板中,或放入一个小助手中。我会告诉你这两种方法。
让我们假设您的上下文如下所示:
{
"cherry": false,
"berry": true
}
此方法需要 dustjs-helpers >= 1.6.2
您必须包含两个 {@eq}
检查。因为您使用的是最新版本的 Dust,所以您可以访问 {@any}
和 {@none}
助手。
{@select key=cherry}
{@eq value="true" type="boolean"/}
{@eq key=berry value="true" type="boolean"/}
{@any}path/to/template1{/any}
{@none}path/to/template2{/none}
{/select}
您必须在第二个真值测试中手动将 key
覆盖为 berry
。
适用于所有版本的 dustjs-helpers。
{@eq key=cherry value="true" type="boolean"}
path/to/template1
{:else}
{@eq key=berry value="true" type="boolean"}
path/to/template1
{:else}
path/to/template2
{/eq}
{/eq}
缺点:这不能扩展,它很丑,它会重复数据。
根本不需要 dustjs-helpers。
{
"cherry": false,
"berry": true,
"isFruit": function(chunk, context) {
return context.get("cherry") || context.get("berry");
}
}
{?isFruit}
path/to/template1
{:else}
path/to/template2
{/isFruit}
优点:您可以在不更改模板的情况下添加更多条件。
关于dust.js - 如何在 Dust 模板中运行或调节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29140924/
我在 Flask 中创建了 3 个基本的 html 页面。我创建了一个简单的调查问卷,其中包含复选框和单选按钮,如下图所示。我希望能够添加一个条件,例如,如果(男性+乐器+足球+ Volley )则应
我正在开发一个过滤器函数,它可以使用许多参数进行过滤,为此我正在使用 Java Streams。这就是我的代码: public void filter(String cours,String prof
第一个问题 我想使用变量 don_settings[don_btn_act] (=checkbox) 来定义按钮操作。 IF don_settings[don_btn_act] IS on THEN
我有 2 个表: 反馈:faceid (as int), Poolid (as int), deleted (as boolean) 池:id(作为 int),取消(作为 boolean) 除了某些行
正如文档所说: https://xgboost.readthedocs.io/en/latest/parameter.html#general-parameters alpha [默认值=0,别名:r
我需要调节 Mechanize 实例与 API 连接的频率(每 2 秒一次,因此将连接限制在这个或更多) 所以这样: instance.pre_connect_hooks << Proc.new {
有没有办法调节通过 SKAction 播放的声音的音量 playSoundFileNamed:waitForCompletion: . 我想在我的游戏中实现一个简单的音乐和音效 slider 。我可以
所以首先,我之前并没有任何 Javascript 经验,因此为什么我在像这样基本的东西上苦苦挣扎。我很确定那里有答案,但由于英语不是我的母语,我似乎找不到它。 我正在开发一个网站,其中多个票务公司的票
如何在 C++ 中调节 SDL Sprite 速度,我知道这与帧率有关,但我不是 100% 确定。我知道如何在 PyGame 中执行此操作,但 SDL 和 C++ 略有不同。 最佳答案 建议遵循 la
我的网站中有以下代码行: HTML: Paragraph JavaScript/jQuery: var ele = $('.post-body
假设我有一个列表,其默认状态和事件状态由类决定,例如: item1 item2 active item3 active item4 我需要根据列表中的事
我是一名优秀的程序员,十分优秀!