【发布时间】:2015-03-29 20:23:53
【问题描述】:
我有一个小型 hapijs 应用程序,想从辅助模块中显示 json 格式的引号,但我无法显示它。
index.js:
server.views({
engines: {
html: require('handlebars')
},
context: defaultContext,
relativeTo: __dirname,
path: './views',
layoutPath: './views/layout',
helpersPath: './views/helpers',
partialsPath: './views/partials',
layout: false,
isCached: false
});
server.route({
method: 'GET',
path: '/quotes',
handler: function (request, reply) {
reply.view('quotes');
}
});
quotes.html:
<h1>Word of the day by {{{ quotes }}}</h1>
{{{quotes}}}
quotes.js:
module.exports = function () {
var quotes = [
{ author: "Kobayashi Issa", text: "What a strange thing!<br>to be alive<br>beneath cherry blossoms." },
{ author: "Kobayashi Issa", text: "Summer night--<br>even the stars<br>are whispering to each other." },
{ author: "Kobayashi Issa", text: "Never forget:<br>we walk on hell,<br>gazing at flowers." },
{ author: "Kobayashi Issa", text: "Here<br>I'm here-<br>the snow falling." }
];
var id = Math.floor(Math.random() * quotes.length);
return quotes[id].text;
};
如果我返回引号[id],我会在浏览器中获得“[object Object] 的每日词汇”。如果我将车把 html 更改为 {{{ quotes.author }}} 它是空的。 hapijs 中是否有需要调整车把的东西?
我试图做一个 {{#each quotes}} ... {{/each}} 但它没有循环。如果我返回 JSON.stringify(quotes[id]);我得到了 {"author":"Kobayashi Issa","text":"多么奇怪的事情! 活着 樱花下。”}
我知道引号被调用了两次。
问候 克劳斯
【问题讨论】:
标签: javascript handlebars.js hapijs