将handlebarss变量传递给客户端js文件 [英] Pass handlebars variable to client js file
本文介绍了将handlebarss变量传递给客户端js文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用node.js + express + handlebars构建一个应用程序,并且正在寻找一种方法,可以将handlebars数据从服务器传递到客户端javascript文件.例如:
I'm building an app using node.js + express + handlebars and was looking for a way i can pass handlebars data from the server to client-side javascript files. For example:
//server.js
var person = {
name: George,
age: 32,
}
res.render('../views/person', person)
我希望能够在客户端使用person对象,例如:
I want to be able to use the person object on the client side such as:
//client.js
console.log(person.age);
console.log(person.name);
有人可以帮忙吗?
谢谢!
推荐答案
尝试一下
res.render('../views/person', {person: person})
这篇关于将handlebarss变量传递给客户端js文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文