pug是如何使用的?
我是stackoverflow的新手。我的问题包括kml和pug。我的kml文件如下:
<Document>
<Placemark id="LIB02">
<name>Agincourt</name>
<description>Address: 155 Bonis Ave., Toronto, ON, M1T 3W6<br/>Link: https://www.torontopubliclibrary.ca/detail.jsp?R=LIB02</description>
<address>155 Bonis Ave., Toronto, ON, M1T 3W6</address>
<phoneNumber>416-396-8943</phoneNumber>
<Point>
<coordinates>-79.29342962962961,43.78516666666665</coordinates>
</Point>
</Placemark>
</Document>
我需要使用pug访问占位符的id,并将其传递给我的库javascript函数。我的pug文件如下:
li
- var id = library.querySelector("Document.Placemark/{id}").; //THE ERROR LIES HERE
- var p = library.querySelector("name").textContent;
a(href=`/libraries/${p}`) #{p}
如何获取我的Placemark的id?
如果您已经将占位符分配给库,您可以使用获取其id
library.id
- 通过
HtmlWebpackPlugin
将pug渲染为静态HTML - 在JavaScript中加载pug,如
const tmpl = require('template.pug')
- webpack.config.js
- 使用哪种pug装载机
- 服务器端渲染
您应该将具体数据传递到pug中。例如,如果您在JavaScript:中加载pug
const tmpl = require('template.pug');
const name = library.querySelector("name").textContent;
const renderedHtml = tmpl({
name,
// ... pass other data
});
pug
li
a(href=`/libraries/${name}`) #{name}
renderedHtml
包含可以在DOM中反插入的HTML字符串。