I have a web app that is built using Express for node.js. I'm using Jade template files for the HTML displays. In one of these displays I'd like to have the various fields pre-populated with data. The data is being stored in a mongodb session store, as well as in a separate collection in the db. I'd prefer to use the session data to pre-populate these fields in the HTML/Jade displays. How can I go about doing this (if it's possible)?

Add the defaults to res.locals and then set the input elements value attribute in jade.

//node.js app.get('/', function(req, res){ // Sorry I am unfamiliar with Mongo, not sure the syntax... mongo.get('defaults', function(err, body){ res.locals.dName = body.defaultName; res.locals.dFoo = body.defaultFoo; res.render('myTemplate'); }); }); //myTemplate.jade !!! html body form(action='/form', method='post') input#formName(name='name', value=locals.dName) input#formFoo(name='foo', value=locals.dFoo)

本文前端(javascript)相关术语:javascript是什么意思 javascript下载 javascript权威指南 javascript基础教程 javascript 正则表达式 javascript设计模式 javascript高级程序设计 精通javascript javascript教程

本文标题:Prefill HTML / Jade of a Web application Express / node&am ...

技术大类 技术大类 | 前端(javascript) | 评论(0) | 阅读(34)