我是菜鸟。我正在使用 Prototype.KIT 框架使用 nunjucks 创建交互式 HTML 原型。
通常我们使用以下方法将某些属性分配给 HTML 页面上的元素,
label: {
text: "Some text"
},
name: "someAttributeValue",
value: data['someAttributeValue'],
在另一个页面上,我们引用该值并使用,
显示它key: {text: "Some text"},
value: {text: data['someAttributeValue']},
如果 someAttributeValue 为空,如何显示默认值(例如“0”)?
我已经尝试过这些变体,但不起作用,
value: data['someAttributeValue' || "0"],
value: data['someAttributeValue' = "0"],
value: data['someAttributeValue'] = "0",
如果
data['someAttributeValue']
返回 null
或 undefined
,您可以使用以下命令默认为“0”:
value: data['someAttributeValue'] || "0"