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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:56:28+00:00 2026-06-09T18:56:28+00:00

The situation I’m trying to render an overview of a nested data structure with

  • 0

The situation

I’m trying to render an overview of a nested data structure with models and collections.
In particular, i’m loading a SubjectsCollection, where each subject has a few attributes, one of which is supposed to be a nested LessonsCollection.

My Controller loads the SubjectsCollection.
Once the SubjectsCollection is loaded, the controller then renders a SubjectListView (a Marionette.CollectionView) with the SubjectsCollection and shown in a Marionette.Region.

Each SubjectModel within the SubjectListView gets rendered as a SubjectLayout (a Marionette.Layout).

Once the SubjectListView is shown in the Marionette.Region, a function cycles through the SubjectLayout‘s and triggers an event (package-definition:subject:layout:ready) on App.vent (a Marionette.EventAggregator) for each SubjectLayout, passing the SubjectLayout as an argument for any Callbacks to receive.

The desired effect

A method called openLessons reacts to the package-definition:subject:layout:ready event and loads a LessonsCollection. This should happen multiple times (Once for each SubjectLayout that was rendered).

Each LessonsCollection should render a LessonsListView and the LessonsListView should be shown in a region in the SubjectLayout of the SubjectsCollection to which they belong.

The SubjectLayout instance is supposed to be passed as an argument to the openLessons method, so each LessonsListView can be shown in the assigned region of it’s corresponding SubjectLayout.

The Code

Here’s the code I’ve got so far:

var PackageDefinition_Overview_Controller = Controller.extend({

  ...

  Data: {
    packageDefinition: {
      // attributes: {
      //   foo: 'bar',
      //   subjects: [{
      //     attributes: {
      //       baz: 'quux',
      //       lessons: []
      //     }
      //   }]
      // }
    }
  },

  // Initialization
  //---------------
  initialize: function() {

    ...        

    this.bindTo(App.vent, "package-definition:subject:layout:ready", this.openLessons);
  },

  ...

  openSubjects: function(packageDefinitionOverviewLayout) {
    var that = this,
        packageDefinition = packageDefinitionOverviewLayout.model;
        packageDefinition_id = packageDefinition.get('id'),
        subjects = packageDefinition.get('subjects') || new SubjectsCollection(),
        subjectsRegion = packageDefinitionOverviewLayout.subjects;

    ...

      subjects.load(packageDefinition_id);

    ...

    subjects.isLoaded.done(function() {
      packageDefinition.set({
        subjects: subjects
      });
      that.showSubjectListView(subjectsRegion, subjects);
    });

    ... 

  },

  openLessons: function(subjectLayout) {
    var that = this,
        subject = subjectLayout.model;
        subject_id = subject.get('id'),
        lessons = subject.get('lessons') || new LessonsCollection(),
        lessonsRegion = subjectLayout.lessons;

    ...

      lessons.load(subject_id);

    ...

    lessons.isLoaded.done(function() {
      console.log('Data', that.Data);
      subject.set({
        lessons: lessons
      });
      that.showLessonsListView(lessonsRegion, lessons);
    });

    ...

  },

  ...  

  showSubjectListView: function(region, subjects) {
    var subjectsListView = new SubjectsListView(subjects);
    region.show(subjectsListView);

    // Time to load the Lessons
    subjectsLayouts = subjectsListView.children;
    _.each(subjectsLayouts, function(subjectLayout) {
      App.vent.trigger("package-definition:subject:layout:ready", subjectLayout);
    }, this);
  },

  showLessonsListView: function(region, lessons) {
    var lessonsListView = new LessonsListView(lessons);
    region.show(lessonsListView);
  }

});

The problem

Despite the the fact that package-definition:subject:layout:ready gets triggered multiple times, and multiple LessonsCollection‘s get loaded. Only the last SubjectLayout receives its LessonsListView.

Also, each SubjectsCollection‘s ‘lessons’ attribute contains the very last LessonsCollection that got loaded.

So obviously there’s a scoping problem here.

The questions

The questions are:

  1. Why do all SubjectsCollection get their ‘lessons’ attribute overwritten with the last LessonsCollection?
  2. Why does only the last SubjectLayout instance receive a LessonsListView?
  3. How do I resolve the problem?
  • 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-09T18:56:30+00:00Added an answer on June 9, 2026 at 6:56 pm

    Solved

    Well, that’s a bit embarassing.. Turns out the problem all along was I accidentally defined some vars in the global scope, such as here:

    var that = this,
      subject = subjectLayout.model; // <-- should've been a comma... *headdesk*
      subject_id = subject.get('id'),
      lessons = subject.get('lessons') || new LessonsCollection(),
      lessonsRegion = subjectLayout.lessons;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Situation: I want to provide a website service where users can enter some data
Situation: I am trying to write a efficient query using "LIKE" statement to look
Situation: I have a DAY structure. The DAY structure has three variables or attributes:
Situation: One WebApplication, two site collections. Both site collections have the same type and
Situation In my Wicket application, I have a page which contains two tags. Each
Situation: I am trying to construct a simple method that accepts two different integers
Situation: I want to track some Data with Google Analytics on the server-side. Problem:
Situation: I have several Gridviews on one page, and each Gridview has a dynamically
Situation: My current links are generated by the following yii methods: <?php echo CHtml::link(CHtml::encode($data->name),
Situation: an Excel 2010 workbook is created using data from oracle. A data connection

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.