【问题标题】:KeystoneJS with pug template, variables not displaying properly带有哈巴狗模板的 KeystoneJS,变量无法正确显示
【发布时间】:2018-07-31 05:53:33
【问题描述】:

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

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

这是我的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');
};

【问题讨论】:

    标签: pug keystonejs


    【解决方案1】:

    我想通了,你要么使用#{ticket.priority} 要么使用a(href="", rel="tag")=ticket.category

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-30
      • 1970-01-01
      • 2017-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多