我是 jade 的新手,正在尝试创建一个网站,其中服务器上的某些数据的上下文正在发生变化。由于我需要添加未知数量的 div,我认为它应该看起来像这样:
html
head
title Match Support
body
script(type='text/javascript' src='http://code.jquery.com/jquery.min.js')
h1 Some same
h3 Games:
#container
script.
//var matches = JSON.parse(!{match});
var matches = !{matchList};
for (var i = 0; i < matches.length; i++){
// how to add to #container from here?
}
我尝试过使用 JQuery 但无法使其工作。
任何帮助将不胜感激!
最佳答案
如果从服务器异步获取数据,这不是jade的问题,而只是一个jquery向DOM添加元素的问题,例如
matchList.forEach(function(match) {
var a = "<a class='ui label'>" + match.property + "</a>";
$('#container').append(a);
}
如果你渲染 *.jade 页面并在那里传递一些数据,那么你可以在 jade 中使用 for-loop
.ui.segment#container
each match in matchList
a.ui.label
| #{match.property}
关于javascript - 从jade脚本添加到html元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38459773/