我使用node.js,express,jade和socket.io,我可以獲得在jade端運行的javascript代碼,但是我無法生成來自腳本的html。塊從javascript傳遞值到玉器
我不得不根據您的輸入更新我的問題。以下是文件:
server.js
app.get('/', function (req, res) {
res.sendfile(__dirname + '/index.html');
});
io.on('connection', function (socket) {
socket.emit('news', { hello: res}); // res is the reponse object
socket.on('my other event', function (res) {
console.log("socket.io connected and data sent to jade");
});
});
layout.jade:
doctype html
html
head
title= title
script(src='components/jquery/dist/jquery.min.js')
script(type='text/javascript' src='https://cdn.socket.io/socket.io-1.0.6.js')
script(type='text/javascript' src='https://cdnjs.cloudflare.com/ajax/libs/jade/1.11.0/jade.min.js')
script(type='text/javascript' src='https://cdnjs.cloudflare.com/ajax/libs/jade/1.11.0/runtime.min.js')
script.
var socket = io.connect('http://localhost:8898/');
socket.on('news', function (data) {
var photo = data.hello.data[0].images.original.url;
});
body
block content
img(src="#{photo}") // <--- issue here, creates "undefined" image
index.jade:
extends layout.jade
img(src="#{photo}") // my problem is here, creating <undefined> tags in html
也許,但是我從express生成的玉模板完全消失了。 – staminna