我正在尝试根据两个变量的状态使div在其中有一个位置,例如,如果$city = 'New York'
和$state = 'NY'
div将显示New York, NY
。但是,它不起作用,我认为它与范围界定有关。这是我的玉:
$city = data.City
$state = data.State
$locString = ""
if $city != ""
$locString = $locString + $city
if $city != "" && $state != ""
$locString = $locString + ", "
if $state != ""
$locString = $locString + $state
.location #{$locString}
这结束时$ locString为空,但如果我在if语句中打印$ locString,它只有最近添加的值,表明它在每个if语句中重新声明变量的本地副本。我在参考http://jade-lang.com/reference/
中找不到任何相关内容答案 0 :(得分:0)
我建议:
- var city = data.City
- var state = data.State
- var locString = ""
if city != ""
- locString = locString + city
if city != "" && state != ""
- locString = locString + ", "
if state != ""
- locString = locString + state
照顾“var”和“ - ”。
检查“变量”部分 - > https://naltatis.github.io/jade-syntax-docs/