我想要用d3顯示一些存儲在MongoDB中的數據。我的問題是關於通過JADE模板爲每個數據創建div
元素以及之後調用繪製不同圖表的方法的最佳實踐。
我的主要問題是在顯示HTML文件後我失去了對數據的引用,並且我不想再次查詢數據庫。在expressjs和JADE環境中對數據進行可視化
模式
# 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
Afterwads的index.JADE用於創建divs
每執行一次component
[0]
- 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方法。有任何想法嗎?
謝謝。
謝謝你的回答。現在我正在構建div,並通過ajax調用添加數據。 – caiuspb
這就是我將如何做到這一點。一次渲染視圖等視圖。在另一個進程中獲取數據。除非你正在尋找超級超級快速,那麼只需渲染服務器上的所有內容,並且不使用任何javascript :) – Zlatko