为了账号安全,请及时绑定邮箱和手机立即绑定

HTML 表单在 Handlebars 视图中不显示正确的数据

HTML 表单在 Handlebars 视图中不显示正确的数据

慕容森 2023-01-06 11:15:10
在使用 sequelize 和 postgresql(由 brad traversy 提供)创建一个快速应用程序时,我第一次使用 handlebars。填写表单后,我使用 Joi 来验证请求主体,如果出现错误,我会重新呈现表单(视图)并保留最初输入的值。问题是发生这种情况时,文本会被自动修剪。EG 我用“Hello World”填写标题字段并且不填写表单中的其他字段,Joi 会不高兴所以我重新呈现表单(视图)并且当标题重新填充到表单中时,它会只是说“你好”。千兆资源的发布端点// Add a Gigrouter.post("/add", (req, res) => {    let { title, technologies, budget, description, contact_email } = req.body;    const { error } = validateGig(req.body);    if (error) {        // Re-Render The Form        return res.status(400).render("add", {            error: error.details[0].message,            title,            technologies,            budget,            description,            contact_email        });    } else {        budget == "" ? (budget = "Unknown") : (budget = `$${budget}`);        // Make Lower Case and Remove Space After Comma        technologies = technologies.toLowerCase().replace(/, /g, ",");        // Insert Into Table        Gig.create({            title,            technologies,            budget,            description,            contact_email        })            .then((gig) => res.redirect("/gigs"))            .catch((err) => console.log("Error Adding Gig" + err));    }});
查看完整描述

1 回答

?
Smart猫小萌

TA贡献1911条经验 获得超7个赞

在模板中使用变量时,您仍需要在属性值两边加上引号。

例如:

value={{title}}

应该写成

value="{{title}}"


查看完整回答
反对 回复 2023-01-06
  • 1 回答
  • 0 关注
  • 90 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信