【发布时间】:2019-04-06 08:17:53
【问题描述】:
我正在尝试从 mongodb 中显示选定的选项。我曾多次尝试通过检查不同的来源来解决这个问题。我收到此错误(错误:缺少助手:“选择”)
这是我的 handlebar_helper.js 文件
module.exports = (Handlebars)=>{
Handlebars.registerHelper('select', function(selected, options) {
return options.fn(this).replace(new RegExp('value = \"'+ selected + '\"'), '$&selected="selected"');
});
};
这是我的主文件 app.js
const {select} = require('./helpers/handlebars_helpers');
app.engine('handlebars', exphbs({defaultLayout: 'home', helpers: {select: select}}));
app.set('view engine', 'handlebars');
这里是edit.handlebars
{#select post.status}}
<option value="public">Public</option>
<option value="private">Private</option>
<option value="draft">Draft</option>
{{/select}}
【问题讨论】: