【发布时间】:2014-01-23 07:39:54
【问题描述】:
我是 nodejs 的新手,正在尝试为 html 内容 myfile.jade 创建一个玉文件:
以下是文件内容:
extends layout
block content
script
function capitalize(s) {
console.log("Testing js exec");
return s.charAt(0).toUpperCase() + s.slice(1);
};
table
- each item in list
tr
td
a(href="/collection/#{item.name}") #{capitalize(itemName)}
但是,运行时会抛出以下错误:
Error: mweb/views/collections.jade:8
6| script
7| function capitalize(s) {
> 8| console.log("Testing js exec");
9| return s.charAt(0).toUpperCase() + s.slice(1);
10| };
unexpected text ;
如果我删除 console.log,它会抛出错误:
TypeError: mweb/views/collections.jade:18
> 18| a(href="/collection/#{item.name}") #{capitalize(itemName)}
据我所知,在jade编译期间正在调用capitalize,并且该功能不可用,因为脚本标签也被编译到html中。对我来说评估此电话的最佳方式是什么 a) 服务器端或 b) 客户端?
谢谢
【问题讨论】:
标签: javascript node.js express pug