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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:58:07+00:00 2026-05-26T11:58:07+00:00

I am working on a backbone.js application with rails api which provides the json

  • 0

I am working on a backbone.js application with rails api which provides the json as shown:

{
    "name": "dan brown",
    "genre": "fiction",
    "books": [{
        "title": "Da vinci Code",
        "price": "50"
    },
    {
        "title": "Some other name",
        "price": "45"
    }],

    "name": "Author1",
    "genre": "comedy",
    "books": [{
        "title": "asdfasdfdsf",
        "price": "50"
    },
    {
        "title": "asdfdsf name",
        "price": "45"
    }]
}

Todo: 1. TO display the list of authors on the left side of the page.
2. When the user clicks on the author, corresponding books should be displayed with a link to add_to_cart
3. Finally when the user clicks on the book, it should display more details about that book

Progress: 1. I am able to get the list of authors using backbone.js and display on the left side (authors.fetch())
2. And i was able to get the books of that particular author to show up when user clicks.

Problem: Now When the user clicks on the AUTHOR1 for the first time it’ll display the books of that author BUT after clicking on some other author, if the user clicks on the same Author1 again no books are displayed.. It seems user Backbone author model losing the click event after it’s clicked once….And I want the to click event to persist on the authors…

WHAT TO DO ?

WHERE TO DO ?

Any Help and Suggestions are highly appreciated

In AuthorView

events: {
    "click .author": "select"
},

select: function() {
    this.collection.trigger('select', this.model);
    //console.log(this.model);
}

In BookListView:

this.collection.bind('add', this.renderBook);

this.book = this.options.book;

this.authors = this.options.authors;
this.authors.bind('select', this.queueBooks);

queueBooks: function(author) {
    this.collection.add(author);
}

I’m guessing that the problem lies in the queueBooks: method, when a model is added to the
collection it fires a add event which then is used to render the books through renderBook callback…So i think if the model already exists in the collection it doesn’t fire the add the event again thereby not rendering the books….How to solve this??????!!!!!!!!!!!!!!!

EDIT: As suggested by Derick-

this.authors = this.options.authors;
this.authors.bind('select', this.renderBooks);

This works perfectly BUT this way no add event is generated in the collection as no model is bieng added…..the reason i want the book models in the BookList collection is to have a filter on the booklist collection so that they can be filtered based on prices, and other criteria, Is there any way to implement these features?????????

  • 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-26T11:58:07+00:00Added an answer on May 26, 2026 at 11:58 am

    I’m guessing that the problem lies in the queueBooks: method, when a
    model is added to the collection it fires a add event which then is
    used to render the books through renderBook callback…So i think if
    the model already exists in the collection it doesn’t fire the add the
    event again thereby not rendering the books

    That is correct. You can only add a model to a collection once. It will throw a JavaScript error when you try to add it the second time.

    You already have everything you need in place, you’re just listening to the wrong events and doing things in the wrong order. Instead of adding a model to the collection to display it, you need to listen to the select event of the model, and use that to display it.

    this.authors = this.options.authors;
    this.authors.bind('select', this.renderBook);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a backbone.js application with rails api which provides the json
Currently I'm working on a Server-Client system which will be the backbone of my
I'm trying to get my backbone associations working inside a rails app , and
We're designing a backbone application, in which each server-side collection has the potential to
Working with dates in ruby and rails on windows, I'm having problems with pre-epoch
Working with python interactively, it's sometimes necessary to display a result which is some
Working with an Oracle 9i database from an ASP.NET 2.0 (VB) application using OLEDB.
Working on an iPhone application through a TightVNC connection into a Mac Mini; the
Background I'm working on a an educational JavaScript application/site (SPA) that will eventually have
I have a single page jquery mobile application in which there are few parent

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.