【发布时间】:2014-03-26 20:35:06
【问题描述】:
我正在尝试使用存储在 MongoDB 中的 d3 可视化一些数据。我的问题是关于通过 JADE 模板为每个数据创建 div 元素的最佳实践,然后调用一个方法来绘制不同的图表。
我的主要问题是在显示 HTML 文件后丢失了对数据的引用,我不想再次查询数据库。
架构
# Create Schema
executionSchema = new Schema(
timestamp: Number,
components: [{
uid: String,
type: { type: String },
samples: [Number],
execution_times: [Number]
}]
)
最初检索数据并将其提供给 JADE 模板:
索引咖啡
exports.index = (req, res) ->
Execution.find (err, executions, count) ->
res.render "index", title: "Debugger", executions: executions
return
return
之后,index.JADE 在执行[0] 内为每个component 创建divs
- each component in executions[0].components
div(class="panel panel-primary")
div(class="panel-heading") UID: #{component.uid}
div(class="panel-body")
p(style='white-space:pre;')
| Type: #{component.type}
- var uid = component.uid
div(id=uid)
这就是现在的一切,因为我无法在 JADE 文件之外调用 JavaScript 方法。有什么想法吗?
谢谢。
【问题讨论】:
标签: javascript node.js express mongoose pug