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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:47:16+00:00 2026-05-29T04:47:16+00:00

Help me to find best approach for managing Backbone views. For example I have

  • 0

Help me to find best approach for managing Backbone views.

For example I have a collection of views MyCollectionView which consists of MyModelView – views of each model in the collection.

And what if I want to hide/show some models on the page?

Now I am following this way:

  • Use collection.each for every model
  • Inside of loop I call model function filter with some params
  • In this function I check model properties and call model.trigger 'hide' or model.trigger 'show'
  • And finally in the model view I use this.model.bind 'hide', this.hide, this where actually I use .hide() or .show()

This way seems me awful… Why do I need to do this long chain of functions and events. Does any simplest approach exist?

Thanks!

  • 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-29T04:47:19+00:00Added an answer on May 29, 2026 at 4:47 am

    Your models shouldn’t be telling views what they should do – they are supposed to represent data and shouldn’t take part in controlling the application – so no wonders it feels wrong to you 🙂

    The more elegant way would be to add a filter method to the MyCollectionView which would use underscore methods to filter the views you want to show/hide and do its job of well… doing that – picking which models should be shown. Then having hte array of matches just call a method for rendering the list and pass your array of models to it so it can render the views for matching models.

    From my experience of creating such filters I can tell you that it might be much more efficient for longer lists to remove whole list do filtering on collection level and render again only the views which are matching the filter query. jQuery hide/show can be a bit taxing – though it’s a concern you will have only with large amount of data/views.

    Also! Take advantage of the underscore methods bound to the collection – you don’t need to do collection.each(... you can just do

    var matches = collection.filter(function(model) { 
        return /*matching condition*/;
    });
    

    (Also remember to use documentFragment when rendering lists and appending to the DOM pre-generated list of views rather then appending them one by one)

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

Sidebar

Related Questions

Can some one help me to find the best approach? Its is documentcloud. References
Please help me to find out error in my SQL query. I have created
I hope I will find a help here. I have a quite complex MVC
I am trying to find some code which will help me to find out
Help me to find best way for replacing version variable in my ui.xml <gwt:HTML>
I need a jquery ninja to help me find the best jquery selector to
I have searched alot on google and in here to find the best featured
I think Im taking the wrong approach to this and have tried to find
I'm new to simulation and i just wanted to find out the best approach
Could you please help me find out the time complexity of the Fleury' algorithm

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.