我在jade中有以下视图,它显示了json城市,但是当环入以获取cityName时它是空的
p #{cities}
p
label(for='from') From
select#sourcecity(name="sourcecity", required="required")
each sourceCity in cities
option(value="#{sourceCity.cityId}") #{sourceCity.cityName}
p#{cities}
[{"cityId":79,"cityName":"Lenggong"},{"cityId":64,"cityName":"Gemas"},{"cityId":87,"cityName":"Jerteh"},{"cityId":36,"cityName":"LCCT"},{"cityId":95,"cityName":"Genting Highlands"},{"cityId":57,"cityName":"Pengkalan Kubor"},{"cityId":2,"cityName":"Kuala Lumpur"},{"cityId":3,"cityName":"Melaka"},{"cityId":15,"cityName":"Seremban"},{"cityId":28,"cityName":"Kangar"},{"cityId":63,"cityName":"Bahau"}]
答案 0 :(得分:0)
由于您似乎建议p #{cities}
将看起来作为对象呈现,我认为您将JSON 字符串传递给Jade。< / p>
这样的事情:
res.render('page', {
cities : '[{"cityId":79,"cityName":"Lenggong"},...]'
});
但是Jade需要传递一个实际的对象:
res.render('page', {
cities : JSON.parse('[{"cityId":79,"cityName":"Lenggong"},...]')
});