バージョン0.4.0でSparkテンプレートエンジンを導入したことで、この問題に対処する{{#constant}}ブロックヘルパーが導入されました。私は時々まし
http://meteor.com/blog/2012/08/31/introducing-spark-a-new-live-page-update-engine
あなたのHTMLテンプレートが
<template name="samplePageTemplate">
<div id="samplePage" class="page">
{{#constant}}
<div id="sampleGraph"></div>
{{/constant}}
</div>
</template>
....このようになるはずとJavaScriptは次のようになります...
Template.samplePageTemplate.destroyed = function() {
this.handle && this.handle.stop();
};
Template.samplePageTemplate.rendered = function() {
self.node = self.find("svg");
if (!self.handle) {
self.handle = Meteor.autorun(function(){
$('#sampleGraph').html('');
renderChart();
});
};
};
function renderChart(){
// lots of d3 chart specific stuff
var vis = d3.select("#sampleGraph").append("svg:svg")
.attr("width", window.innerWidth)
.attr("height", window.innerHeight)
.append("svg:g")
.attr("transform", "translate(" + m[3] + "," + m[0] + ")");
// more d3 chart specific stuff
});
};
self.handleではなくself.nodeを使用しなければなりませんでしたが、それ以外の場合はかなり単純です。
プログラムで埋め込まれた要素を保持するには、良い方法を追加する必要があります。問題は、テンプレートが再レンダリングされるときに、DOMにあるものをレンダリングされたものに置き換えます。つまり、他の手段でどの要素が追加されたのかわかりません。 – dgreensp
@dgreensp - これは機能であり、欠陥ではありません。 ;) – AbigailW