javascript - 通过 Nunjucks Templating 在 json 对象中添加数据
问题描述
我在其中创建了数据对象和特征数组。我正在尝试通过 nunjucks 变量添加数据,但它显示模板渲染错误。
mydata = {
"type": "collection",
"features" : []
};
{% for piece in data.pieces %}
mydata.features.push({
type: "Feature",
properties: {
title: '{{ piece.title }}',
startDate: '{{ piece.startDate }}',
endDate: '{{ piece.endDate }}'
},
geometry: {
type: "Point",
coordinates: "abc"
}
});
{% endfor %}
我的结果应该是这样的。
mydata = {
"type": "collection",
"features": [
{
"type": "Feature", "properties": {"title": "", "startDate": "", "endDate": ""
},
"geometry": {
"type": "Point","coordinates": [ ]
}
]
}
解决方案
推荐阅读
- c# - 获取内存可变结构的正确方法
/ 跨度 ? - c# - 从 dotnet core 1 迁移到 dotnet core 2.1 后应用程序变慢
- airflow - 如何更改气流/作曲家的日志级别
- swift - StorageMetadata' 没有成员 'downloadURL'
- java - Xamarin.Android Notification.Notify 什么都不做
- algorithm - 确保独特的 Futoshiki 解决方案的最少线索数是多少?
- android - 如何使用导航抽屉更改 Android Studio 中的活动
- ruby-on-rails - 在 Rails 5 的同一页面上向服务器发出不必要的链接请求锚点请求
- xml - 如何将 Xmla 文件转换为 Xml 格式
- php - password_verify() 函数被警告为未定义的常量