Collection of javascript garbage knockout model views

I am using knockoutJS as the MVVM client environment.

Sometimes I create temporary view models (via js functions) and assign them to dynamic DOM loads.

When, for example, the comment panel for some content is no longer needed, I remove the comment comments panel from the DOM. What happens to the variable that was used as the view model when I called applyBindings with the DOM element parameter? Is it somehow arranged? Or am I responsible for this? If so, how to do it?

+5
source share
1 answer

Assign your viewModel to a variable:

var viewModel = {...}
ko.applyBindings(viewModel, $("#html-id"));

To destroy viewModel:

ko.cleanNode($("#html-id"));
delete viewModel;
$("#html-id").remove();

, , , / ...

+2

All Articles