开发者

How to pass a method from expressjs to Jade

开发者 https://www.devze.com 2023-03-29 05:09 出处:网络
<b>ExpressJS Code <code> var express = require(\'express\'), YUI = require(\'yui3\').YUI, sys = require(\'sys\'),
<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

0

精彩评论

暂无评论...
验证码 换一张
取 消