如何将一个方法从expressjs传递给Jade

时间:2011-08-17 12:49:30

标签: object pug

<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.

1 个答案:

答案 0 :(得分:0)

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

E.g。

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

然后你可以调用JSON.f