我希望在我的 JADE 模板中包含客户端脚本并编写
扩展布局
script.
function collect_data() {
var transitions = {};
$( ":checkbox:checked" ).each(function (index, element) {
//// some code
}
block content
h1= title
table
- for (var i = 1; i < images.length; ++i) {
- var image;
// and so on
我期待类似的事情
<script>
function collect_data() {
var transitions = {};
...
</script>
在我的网页源代码中,但我没有看到它。
什么是不正确的?如何在 Jade 中将嵌入的 javascript 渲染到模板中?
最佳答案
您正在通过扩展布局
扩展布局
这意味着您处于子模板中,根据 pug 的 docs common mistakes section
Note that only named blocks and mixin definitions can appear at the top (unindented) level of a child template. This is important! Parent templates define a page’s overall structure, and child templates can only append, prepend, or replace specific blocks of markup and logic. If a child template tried to add content outside of a block, Pug would have no way of knowing where to put it in the final page.
这意味着你应该做类似的事情
//- layout.pug
html
head
block head
body
block content
并在子模板中执行类似的操作
extends layout
block append head
script.
function collect_data() {
var transitions = {};
$( ":checkbox:checked" ).each(function (index, element) {
//// some code
}
将使其出现在布局
中的head
部分下
关于javascript - 脚本。 JADE 标签未在 Express 中呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44575383/