我正在繪製一個d3甜甜圈。現在我想添加儘可能多的甜甜圈作爲數據庫中的條目。如果我向數據庫添加某些內容,自動更新失敗。我必須在瀏覽器中重新加載我的代碼 - 然後我看到新的甜甜圈。 Isnt Meteor.autorun自動更新? 代碼是:流星添加d3 grafics動態失敗
Template.donuts.rendered = function(){
var self = this;
self.node = self.find("p");
// Data
var dataset = {
apples: [2, 2, 2, 2, 2]
};
//Width and height
var width = 100,
height = 100,
radius = Math.min(width, height)/2;
// render
self.handle = Meteor.autorun(function() {
var color = d3.scale.category10();
var pie = d3.layout.pie()
.sort(null);
var arc = d3.svg.arc()
.innerRadius(radius - 20)
.outerRadius(radius - 5);
var svg = d3.select(self.node).append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(" + width/2 + "," + height/2 + ")");
var path = svg.selectAll("path")
.data(pie(dataset.apples))
.enter().append("path")
.attr("fill", function(d, i) { return color(i); })
.attr("d", arc);
});
}; //Template.donuts
它通過車把
<template name="donuts">
{{#each nodes}}
<p></p>
{{/each}}
</template>
我在做什麼錯叫。感謝您的時間。