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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:03:09+00:00 2026-06-06T23:03:09+00:00

I need to pass a value to the listView.template in order to be aware

  • 0

I need to pass a value to the listView.template in order to be aware the template about the collection.length.
I think one option is to redefine the serializeData method in order to pass a parameter in this way.

var ListView = Marionette.CompositeView.extend({

    initialize: function () {
        this.collection.on('reset', this.serializeData, this);
        this.collection.on('remove', this.serializeData, this);
        this.collection.on('add', this.serializeData, this);
    },

    serializeData: function () {
        console.log(this.collection.length);
        return {
            has_tasks: this.collection.length > 0
        };
    },

    // other codes
});

When I start the app the collection is not yet fetched so:

1.a) the collection.legth = 0
2.b) the template get has_tasks = false as expected.

2.a) after the fetch the collection.length is > 0,
2.b) the serializeData is called and so it puts the has_tasks = true,
2.c) the template seems to be not rendered because it maintains the has_tasks = false

Any idea because 2.c?

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

    Latest Marionette has solved this problem by calling an optional templateHelpers on the view to provide additional context to the view. Also your event binding is not Marionette-friendly as it it will not be auto-unbound correctly when the view is unloaded. So all you need to do in your view is:

    var ListView = Marionette.CompositeView.extend({
    
        initialize: function () {
            this.bindTo(this.collection, "add", this.render, this);
            this.bindTo(this.collection, "remove", this.render, this);
            this.bindTo(this.collection, "reset", this.render, this);
        },
    
        templateHelpers: function () {
            console.log(this.collection.length);
            return {
                has_tasks: this.collection.length > 0
            };
        },
    
        // other codes
    });
    

    Note, however, that you probably don’t want to rerender the entire view and all the sub-elements every time an item is added or removed. A better approach is to only update the count displayed. For instance:

    var ListView = Marionette.CompositeView.extend({
    
        initialize: function () {
            this.bindTo(this.collection, "add", this.updateCount, this);
            this.bindTo(this.collection, "remove", this.updateCount, this);
            this.bindTo(this.collection, "reset", this.updateCount, this);
        },
    
        updateCount: function() {
            this.$('.count_span').html(this.collection.length);
        },
    
        // other codes
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to pass a value from PHP to C++. I think I can
I need to pass the value from one function to another in JavaScript but
I've some scenarios where i need to pass value type as reference without changed
I have an ASP control custom built and I need to pass a value
I am trying pass class as value in hashmap. I need to get the
I have a HyperLink control in a ListView, and I need to pass a
I need to pass the pass value stored in a asp hiddenfield to a
I'm working with the DeviceIoControl function and I need pass the IOCTL_ATA_PASS_THROUGH value to
I need to pass the value of on of the selected item in the
I need to pass a value as a parameter from ASP.Net application to SSRS

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.