【问题标题】:How to pass a method from expressjs to Jade如何将 expressjs 中的方法传递给 Jade
【发布时间】:2011-08-17 12:49:30
【问题描述】:
<b>ExpressJS Code

<code>
var express = require('express'),
    YUI = require('yui3').YUI,
    sys = require('sys'),
    util = require('util');

var app = module.exports = express.createServer();

app.get('/weather', function(req, res) {
    res.render('weather', {
      title: 'Weather',
      YUI: YUI
    });

</code>

At Jade Side

<code>
h1 test apge
   script(type="text/javascript")
      !=YUI  <<< this returns as text, but i want to access that object YUI
</code> 
How can I pass javascript objects from expressJS to Jade.

【问题讨论】:

    标签: object pug


    【解决方案1】:

    您可以将 JSON 对象传递给翡翠模板,然后使用 JavaScript 解析 JSON。

    例如

    var JSON = {
     f : function(){alert("Hello")}
    }
    

    然后你可以调用 JSON.f

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-18
      • 2013-04-18
      • 2014-05-03
      • 2012-05-25
      • 1970-01-01
      • 2016-06-06
      • 2014-04-15
      • 1970-01-01
      相关资源
      最近更新 更多