Why doesn’t this data display?

微信扫一扫,分享到朋友圈

Why doesn’t this data display?

I have the following JSON object:

{
user:
{
city: 'San Francisco',
country: 'US',
displayName: 'Bernard',
weightUnit: 'METRIC'
}
}

It comes back in the following piece of code, i.e. as a string:

var response = results[0];

I send it to the view like this:

res.render('user', {title: 'User Details', result: JSON.parse(response)});

In the view, no matter what I do, I cannot access displayName.

All I want is to this in my jade template:

h1 Hi, #{displayName}

And I keep getting user undefined, undefined of undefined, etc.

No matter how I try and access that displayName, jade/express simply cannot get to it.

Anyone have any ideas how I’d do this please?

Problem courtesy of: Bernard

Solution

That object that you pass in your render
call becomes the context your Jade file uses. Thus, at your root, you have title
and result
. See where this is going?

Try h1 Hi, #{result.user.displayName}
.

Solution courtesy of: juanpaco

微信扫一扫,分享到朋友圈

Why doesn’t this data display?

南开团队宣布研获新冠病毒SARS-COV2抗体检测试剂盒,可15分钟快速检测

上一篇

Spring Boot 之Spring data JPA简介

下一篇

你也可能喜欢

Why doesn’t this data display?

长按储存图像,分享给朋友