I am just running my code locally. I am using handlebars and JS to accept a get request and display the data back to the page. The data is being received. I know because the data being input into the URL is viewable when I do a console.log on the the query.
But, the data should be displayed back on the html page after it is received, but it is not.
This is the code I am using for the JS
app.get('/junk',function(req,res){
var qParams = [];
for (var p in req.query){
qParams.push({'name':p,'value':req.query[p]})
}
var context = {};
context.dataList = qParams;
res.render('junk', context);
console.log('here');
});
This is handlebars, junk.handlebars:
<h1>You sent the following data in a GET request:</h1>
<ul>
{{#each param}}
<li>{{this.name}}: {{this.value}}
{{/each}}
</ul>
I got it to work with a handlebars file like this:
<ul>
{{#each dataList}}
<li>{{name}}: {{value}}</li>
{{/each}}
</ul>
The main problem seemed to be that you were referencing param
but the array you were looping through in handlebars was actually called dataList
. The list tag also should be closed with a </li>
and the this
appeared to be unnecessary.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.