Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7178821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:59:52+00:00 2026-05-28T16:59:52+00:00

I read this and it seemed to be the answer I was looking for

  • 0

I read this and it seemed to be the answer I was looking for but it doesn’t seem that I understand completely what’s going on. Dynamically choosing a view at runtime with Ember + Handlebars.

FWIW, the ember.StateManager as far as I understand can not work nested. So I wouldn’t be able to use it for a single page app that would switch between an application view and user profile view if the application view had sub-sections in it for example. So I figured there must be another way.

So a simple example to illustrate what I’m trying to do.

     (function($){
  window.APP = Ember.Application.create();
  /*models*/
  $.models = {};
  $.models.c = Ember.Object.create({
                    first_name: "joe",
                    last_name: "blow"
                });

  $.models.a = Ember.Object.create({
                    street:"1 wall street plaza",
                    city: "New York City",
                    state: "NY",
                    zip: "10101"
                });

  //views (sections of the application
  $.views = {};
  $.views.name = Ember.View.extend({template:Ember.Handlebars.compile("{{content.first_name}} {{content.last_name}}"),
                   contentBinding: "$.models.c"
                  });

  $.views.address = Ember.View.extend({template: Ember.Handlebars.compile("{{content.street}} {{content.city}} {{content.state}} {{content.zip}}"),
                 contentBinding: "$.models.a"});

  //something to hold the current view(section)
  $.navmodel = Ember.Object.create({current:$.views.address});

  //view to display the current view(section)
  $.nav = Ember.View.create({template: Ember.Handlebars.compile("{{view current}}"),
                   currentBinding: "$.navmodel.current"
                  }); 

  //add to page
  $.nav.appendTo("#content");

  //switch between the pages
  setTimeout(function(){
        $.navmodel.set("current", $.views.name);
        alert("set");
    },1000);
 })(jQuery);

Yes I realize Ember.StateManager could be used for this, but if I then needed to have nested subviews the StateManager wouldn’t work would it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:59:53+00:00Added an answer on May 28, 2026 at 4:59 pm

    First, I do believe that the Ember StateManager does handle nested states. I can’t give you a concrete example though. I have played a bit with states but that part of Ember.js wasn’t yet stable enough so I stopped in frustration.

    As far as switching views without using a StateManager, this is totally doable. Try swapping your $.nav View with a ContainerView. Something like this should do the trick (beware, untested code!):

    $.nav = Ember.ContainerView.create({
        switchView: function(view) { 
            var childViews = this.get("childViews"); 
            childViews.popObject();      // Remove the current view, if any
            childViews.pushObject(view); // Add the requested view
        }, 
    });
    

    The Ember documentation has a section about the ContainerView which you should take a look at.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, this seemed simple at first, but after crawling Google and here, the answer
This seemed to me like an easy one, but I can't seem to find
I read this PHP RegEx page , but either I'm missing something, misreading something,
I read this answer and its comments and I'm curious: Are there any reasons
I read this answer on SO: Because the recursive mutex has a sense of
I've seen a couple posts about this issue, but so far nothing has seemed
I know this could be a stupid question but I can't seem to actually
I'm making a handler class that will read similar to this: package avian.background {
I read this question/answer however there wasn't any mention of it being a "bad
This seemed like a common question but after doing some searching, I wasn't really

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.