KeystoneJS与pug模板,变量无法正常显示

时间:2018-02-20 19:09:48

标签: pug keystonejs

我正在阅读一本关于KeystoneJS的书,并跟随该项目。他们正在使用Swig,我支持的项目使用帕格。

我不知道如何解决模型的变量。

这是我的ticketlist.pug

Rendered Webpage

extends ../../layouts/default.pug

block content

  .container
    .panel.panel-primary
  .panel-heading Tickets
  .panel-body
    p
      |These are a list of tickets in the system.

  table.table.table-striped
    for ticket in locals.data.tickets 
      tr
        td
          .col-md-1
            span.label.label-info.pull-right ticket.status
          a.bold(href="ticket.url") ticket.title | capitalize
          ul.ticket-meta
            li  
            li
              small Status
              a(href="", rel="tag") ticket.status
            li
              small Priority
              a(href="", rel="tag") ticket.priority
            li
              small Category
              a(href="", rel="tag") ticket.category
            li
              small Last Updated
              abbr.last-updated
              a(href="", rel="tag") ticket._.updatedAt.format('Do MMMM YYYY')
  .panel-footer

以下是来自视图的视图ticketlist.js文件

var keystone = require('keystone');

exports = module.exports = function (req, res) {
  var view = new keystone.View(req, res);
  var locals =res.locals;

  //used to set the currently selected item in nav heading
  locals.section = 'tickets';

  locals.data = {
    tickets: [],
  };

  //Load all tickets
  view.on('init', function (next) {
    var q = keystone.list('Ticket').model.find();

    q.exec(function(err,results){
      locals.data.tickets = results;
      next(err);
    });
  });
  view.render('tickets/ticketlist');
};

1 个答案:

答案 0 :(得分:0)

我想出来了,您必须使用#{ticket.priority}a(href="", rel="tag")=ticket.category