使用Jade显示input值内的数据

我对Jade相当陌生,并且想要显示一些输出的数据作为文本inputvalue 。 喜欢这个:

 input(type="text", name="date", value="THISRIGHTHURR") 

但只有值必须是viewpost.date 。 我尝试了多种方式,似乎没有工作:

 input(type="text", name="date", value=viewpost.date) // doesn't work input(type="text", name="date", value=.=viewpost.date) // doesn't work input(type="text", name="date", value=".=viewpost.date") // doesn't work 

我当然可以通过做一些类似的事情来让它在input之外工作

 each post, i in viewpost h1.=post.date 

我是否也应该循环input ? 这是输出我的viewpostvariables的JS(使用Node和Express)。

 // render show post view exports.viewpost = function(db) { return function(req, res) { var id = req.params.id; collection.find({ "_id": new BSON.ObjectID(id) }, function (err, data) { res.render("viewpost", { "viewpost" : data }); }); }; }; 

您可以尝试在#{}包含variables以输出该variables:

input(type="text", name="date", value="#{viewpost.date}")

Pug 0.1.0(Jade 2.x)删除了对属性插值的支持,所以现在这个工作:

 input(type="text", name="date", value=viewpost.date) 

https://github.com/pugjs/pug/issues/2305

我意识到这是一个旧消息,但是我发现这些都没有奏效,最终这样做,对于像我一样难倒的人:

 input(type="text", placeholder=data.string) 

然后在脚本中:

 $(document).on('focus', 'input', function(){ var text = $(this).attr('placeholder'); $(this).val(text); }) 

谢谢