Joachim H. Skeie
Joachim H. Skeie

Reputation: 1903

Ember.js adding and removing views from the DOM?

I am looking into ember.js, after working with SproutCore 1 previously. I am looking for some examples on how to add and remove views from the DOM as the user navigates the application.

For instance, I have an application that contains a set of cases and each case has a workflow. There are also administration pages, etc.

When the user starts up the app, a dashboard-like user interface is shown. From here the user is able to search or click on a case in order to bring up that case. At this point I want to do the following:

As this will be a somewhat large application I am not sure if toggling the isVisible parameter is sufficient, or if other measures needs to be taken in order to not overload the user's browser.

Is there a guide, or an example that shows how to do this ?

Upvotes: 7

Views: 8903

Answers (1)

Martin Algesten
Martin Algesten

Reputation: 13620

WARNING: OUTDATED ANSWER

A view inherits from Ember.View which means it gets some key methods. append(), which appends to body, appendTo(arg) which takes an argument and remove().

The argument is a jQuery style selector of where to insert the element in the DOM.

// my view
App.PartsView = Ember.View.extend({
    ...
});


// create/insert my view
App.partsView = App.PartsView.create();
App.partsView.appendTo('#partcontainer');

In my code I have a <div id="partcontainer"></div>.

// remove from DOM
App.partsView.remove();

The documentation has a good part on Building a View Hierarchy and later a section on Ember.ContainerView depending on whether you want to do it all programatically or not.

Upvotes: 9

Related Questions