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 7942427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:58:01+00:00 2026-06-03T23:58:01+00:00

I apologize if this has a painfully obvious answer but I am both a

  • 0

I apologize if this has a painfully obvious answer but I am both a JS and Ember noob and I am having trouble finding a solution to what I think is a common scenario. Essentially, I have a multi-page app with html/css/js front end and a java back end with an exposed REST api. I have 1 app.js file that I include in all screens and multiple controllers, some of which only apply to individual screens.

EDIT: Forgot my question. My question is how do I delay the query to my server for my user data until my controller has an observer. Since the controller is present on multiple screens (which dont all need it) I do not want to blindly query on creation of the object since it would be wasteful. For now i have a hacky way of doing it where at the end of my inline script tag of a page I call the populate method. Below is what my code currently looks like.

Section of app.js:

App = Ember.Application.create();

User = Ember.Object.extend({
    username: 'empty',
    fullname: 'empty user'
});

App.UserDataSource = Ember.Object.extend({

    fetchMyUser: function(callback) {
        $.get('ncaa/user', function(data) {
          callback(User.create({
                  username: data.username, 
                  fullname: data.fullname}));
        });
    }
});

App.userDataSource = App.UserDataSource.create();

App.UserController = Ember.Object.extend({

    content: null,

    populate: function() {
        var controller = this;
        this.get('dataSource').fetchMyUser(function(data) {
             controller.set('content', data);
        });
    }
});

App.userController = App.UserController.create({
     dataSourceBinding: Ember.Binding.oneWay('App.userDataSource')
});

Ember.run.sync();

Section of index.html

<script type="text/x-handlebars">
      Welcome, {{App.userController.content.fullname}}
</script>

....other code....
<script type="text/javascript">

     $(document).ready(function() {
           ....other code....
           App.userController.populate();
     });
</script>

I am pretty sure my first steps will be modifying that handlebars template to extend Ember.View but would like to know what the community believes is the best practice. Also, is it wrong for me to try and put all of this in one app.js file? It would be ok to query on creation of my controller if it was only imported on screens that required the user to display.

  • 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-06-03T23:58:03+00:00Added an answer on June 3, 2026 at 11:58 pm

    The answer for my question did end up being in the Ember.View. Essentially what I do is override the init function of my view which adds the call to populate the necessary controller with data. The view is that instantiated via the handlebars template so no more unnecessary calls or hacky work around. Important changes below.

    Index.html:

    <script type="text/x-handlebars">
        {{#view App.UserNameView }} 
            Welcome, {{fullName}}
        {{/view}}
    </script>
    

    App.js:

    App.UserNameView = Em.View.extend({
        init: function() {
              this._super();
              App.userController.populate();
        },
        fullNameBinding: 'App.userController.content.fullname',
        userNameBinding: 'App.userController.content.username'
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I apologize because I know this has been covered over and over again, but
Hopefully no one has asked this question - didn't see it, but I apologize
First off, let me apologize if this has been asked already, but I can’t
I apologize if this has already been asked a different way but I couldn't
I apologize if this has been asked before, but I haven't quite found the
I apologize in advance if folks think this has been beaten to death. I've
I apologize if this question has been asked before, but my case is a
I apologize if this question has been answered elsewhere, but I couldn't seem to
I'm pretty new to rails, so I apologize if this question has an obvious
I apologize in advance if this has been asked before, but I haven't been

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.