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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:36:25+00:00 2026-06-12T10:36:25+00:00

I’m writing an app with EmberJS v1.0.pre. I have an ArrayController which contains a

  • 0

I’m writing an app with EmberJS v1.0.pre. I have an ArrayController which contains a list of all persons. There are a bunch of nested views showing the person, their pets and the notes for each pet.

|----------------------------------------|
| John                                   | <- Person
|----------------------------------------|
|   Quincy (Dog)                         | <- Pet
|     - Super ornery                     | <- Note
|     - Likes XYZ Dog food               |
|     - Will eat your socks              |
|                                        |
|   Tom (Cat)                            |
|    - Always (not) catching mice        |
|                                        |
|----------------------------------------|
| Roger                                  |
|----------------------------------------|
|   V (Dog)                              |
|    - Likes XYZ Dog food                |
|    - Sneezes, but it's ok              |
|                                        |
|----------------------------------------|
| ...                                    |

From the pure MVC standpoint it feels like there should be a controller for each child, but I can’t figure out how to achieve that in Ember. There is the top Array controller and then all the individual views. If I want to delete a note, or edit it, it seems like I need to pass the view’s context up to the controller.

// in the view
click: function () {
  this.get('controller').updateNote(this.get('content'))
}

This feels really bad to me, the View is not supposed to be the authoritative source for data. My assumption is that an ArrayController would instantiate an itemControlerClass along with the itemViewClass.

UPDATE: I have created a fiddle to better illustrate my problem. The functionality is intentionally incomplete, the purpose is to finish the functionality by increasing the content when an item on the list is clicked.

UPDATE: Sorry, I deleted the fiddle on accident! I’m doing some work on a final solution, so I’ll try to create a new fiddle w/ the solution.

  • 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-12T10:36:26+00:00Added an answer on June 12, 2026 at 10:36 am

    “From the pure MVC standpoint it feels like there should be a controller for each child”

    You don’t need a controller for each item, but instead an ArrayController for each collection of objects (People, Pets, Notes). By the way, any actions on child objects (dogs, notes) shouldn’t be passed to App.PersonsController. That would break the Separation of Concerns principle.

    Ember.Router docs cover the case where you want to nest views in a single object ( e.g. /:people_id). But you want to nest views for an array of objects. I can’t think of a way to nest {{outlet}} views, but you can do the following:

    Load the objects People, Pets, Notes in 3 ArrayControllers, and delegate actions on child objects to its corresponding ArrayController.

    App.Router = Ember.Router.extend({
      root: Ember.Route.extend({
        route: '/',
        persons: Ember.Route.extend({
            connectOutlets: function(router) {
    
              router.get('applicationController').connectOutlet('persons');
              // App.Note.find() fetches all Notes,
              // If you are not using ember-data, make sure the notes are loaded into notesController
              router.set('notesController.content', App.Note.find());
              router.set('petsController.content', App.Pet.find());
            }
        })
      })
    });
    

    And then your people template should look like:

    {{#each person in people}}
      <h1>My name is {{person.name}}</h1>
    
      {{#each pet in person.pets}}
         I have a pet with name {{pet.name}}
         <a {{action delete pet target="App.router.petsController">Delete pet</a>
      {{/each}}      
    
      {{view Ember.TextField valueBinding="myNewPetName" type="text"}}
      <a {{action create myNewPetName person target="controller"}}>
        Add a new pet for this person
      </a>
    
    
      {{#each note in person.notes}}
        <!-- delete, create, edit ... -->
      {{/each}}
    

    As you can see, the actions on child objects are delegated to its controller (pet -> petsController), passing the object as the context. In the case of the create action, the controller needs to know to which person the pet belongsTo. Therefore we pass 2 contexts: the person, and the properties of the pet (for simplicity I assumed just a name for the pet).

    In your App.petsControllers you should have actions along the lines:

    App.PetsController = Ember.ArrayController.extend({
       delete: function(e) {
         var context = e.context;
         this.get('content').removeObject(context);
         // Also, if you use ember-data,
         // App.Pet.deleteRecord(context);
       },
    
       create: function(e) {
         var petName = e.contexts[0]
         var person = e.contexts[1];
         this.get('content').pushObject({name: petName, person: person});
         // with ember-data:
         // App.Pet.createRecord({name: petName, person: person});
       }
    });  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
I have an autohotkey script which looks up a word in a bilingual dictionary
I have an array which has BIG numbers and small numbers in it. I
I am writing an app with both english and french support. The app requests
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

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.