Express /把手-无法访问请求对象

时间:2018-11-30 21:00:54

标签: javascript express handlebars.js

我似乎无法弄清楚,我以前曾以相同的格式进行过此工作,将不胜感激!

API请求

router.get("/", function(req, res, next) {
    behance.get({
        api: Behance.APIS.GET_USER_PRODUCT,
        params: { //or simply behance.get('user',
            user:'nolanwagner'
        }
    }, function (error, result) {
        if (error)
        console.log(error)
        else
        res.render('index', { data: result });
        console.log(result);
    });
});

车把模板

{{#data}}
<h1>hi</h1>
{{this.name}}
{{/data}}

我希望这会遍历数据,但是它只给我一个“嗨”,没有数据。 这是我的数据对象。

{
   "projects":[
      {
         "id":72316151,
         "name":"Lost Leaf Cannabis Business Card Design",
         "published_on":1541613239,
         "created_on":1541613209,
         "modified_on":1541613239,
         "url":"https:\/\/www.behance.net\/gallery\/72316151\/Lost-Leaf-Cannabis-Business-Card-Design",
         "slug":"Lost-Leaf-Cannabis-Business-Card-Design",
         "privacy":"public",
         "fields":[
            "Branding",
            "Graphic Design",
            "Illustration"

1 个答案:

答案 0 :(得分:0)

您有一个对象数组,因此请尝试“每个”迭代器:

{{#each this}}
  <p>{{this.name}}</p>
{{/each}}