How to pass a method from expressjs to Jade
<b>ExpressJS Code
<code>
var express = require('express'),
YUI = require('yui3').YUI,
sys = require('sys'),
util = require('u开发者_如何转开发til');
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.
You can pass JSON objects into the jade template, and then parse the JSON using JavaScript.
E.g.
var JSON = {
f : function(){alert("Hello")}
}
You could then call JSON.f
精彩评论