我
JSON.stringify()认为我的客户端脚本需要的任何对象,并插入它作为HTML5
data-whatever属性。
例如:
//app.jsapp.get('/map', function(req, res){ var data = { id: '1234', LL: { lat: 42.1, lng: 80.8, }; res.locals.docsJSON = JSON.stringify([data]); res.render('locations/index');});//jade!!!html body(data-locations=locals.docsJSON) script var docs = JSON.parse($('body').attr('data-locations')); console.log(docs[0].LL);


