我很难使用EJS在脚本中访问NodeJS数据。
以下是相关代码: \路由\ maps.js:
var blankDb = {
"name" : "abcd",
"street" : "123",
"route" : "S Main St",
"city" : "MyCity",
"state" : "SC",
"country" : "United States",
"zip" : "29010",
};
exports.main = function(req, res){
console.log("Request details: " + req.method);
res.render('maps/index.ejs', {cat: 'phar', lat:34.9467, lng:-81.9275, zoom:12, records: blankDb});
};
\视图\ index.ejs:
var category = <%= cat %>;
var lat = <%= lat %>;
var lng = <%= lng %>;
var zoom = <%= zoom %>;
var record = <%= records %>;
这给了我错误:
Uncaught SyntaxError: Unexpected identifier for line 14 i.e. `var record = <%= records %>;`
请帮助!!!