I’m trying to use Blaze.remove() but it’s not working when I store the returned value of renderWithData() as a variable to use to remove the view later.
I’m displaying a list of function names with the code below:
{{#each functionName in functionList}}
<div class="{{functionName}}" id="{{functionName}}">
{{functionName}}
<br>
</div>
{{/each}}
I have a template event function (below). When I render the template with data, I add the returned view to the renderedViews object. The setTimeout function afterwards can remove the view no problem. When I click the div again and it finds that the view already exists by checking the renderedViews object, it is unable to remove the view. No errors are thrown, nothing happens.
'click div': function (event, instance) {
var functionName = event.currentTarget.className;
console.log('event: ' + functionName);
// If the view already exists when the title is clicked, remove it from the DOM
if(renderedViews.hasOwnProperty(functionName)) {
console.log('removing');
Blaze.remove(renderedViews[functionName]);
}
//$(event.currentTarget).append('bloop');
// Render a view and save the view for later so it can be removed
let renderedView = Blaze.renderWithData(
Template.content, // The template being rendered
data(functionName), // The function called for data
event.currentTarget // The DOM node where the template is getting insterted
);
// Store the rendered view in renderedViews object with a property name of functionName
renderedViews[functionName] = renderedView;
//console.log(renderedViews[functionName]);
setTimeout(function() {
Blaze.remove(renderedView);
}, 5000);
}
Am I doing something wrong or is this a bug? Thanks for the help.