【发布时间】:2016-06-04 06:00:36
【问题描述】:
我正在使用 node.js、express、jade 和 socket.io,我可以让 JavaScript 代码在 Jade 端运行,但我无法从脚本生成 html。阻止
我必须根据您的输入更新我的问题。以下是文件:
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
【问题讨论】:
标签: javascript node.js express socket.io pug