简体   繁体   English

我如何渲染玉器文件

[英]how can i render jade file

how can i render jade file and send data as json with socket.io 我该如何渲染玉器文件并使用socket.io将数据作为json发送

render with express 用快递渲染

router.get('/', function(req, res, next) {
    res.render('index', { title: 'Express' });
});

i want something like this 我想要这样的东西

io.sockets.on('connection', function (socket) {
    socket.on("message", function(data) {
        //some think like this
        var a = render('index', { title: 'Express' });
        socket.emit({html:a,more_data:ffffffff});
    });
});

so i render it and add it in object for bass some data with it 所以我渲染它并将其添加到对象中以低音一些数据

Please note: This is an answer to your main question regarding Jade rendering. 请注意: 这是有关Jade渲染的主要问题的答案。 What you do with socket.io is up to you, but of course, you should consider sending only small packets of data back to the browser and do the rendering by client side templates instead. 使用socket.io完全由您决定,但是,当然,您应该考虑仅将少量数据包发送回浏览器,而由客户端模板进行渲染。

However, yes, you can manually render with Jade in Node.js without the need of the Express framework. 但是,可以,您可以在Express。框架中使用JadeJade中手动进行渲染。 Please see Jade API documentation for all the methods and options you can use. 请参阅Jade API文档以获取可以使用的所有方法和选项。

Try this in your app.js: 在您的app.js中尝试一下:

var jade = require('jade');
var renderFunc = jade.compileFile('./views/layout.jade');
var html = renderFunc({ title: 'Express' });
console.log(html);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM