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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:53:03+00:00 2026-06-01T12:53:03+00:00

I’m having an issue that I think is simple to diagnose, but I can’t

  • 0

I’m having an issue that I think is simple to diagnose, but I can’t seem to get it on my own.

I have the following abbreviated Backbone code written in CoffeeScript:

events = FD.Events # collection

# instantiated on page load with collection: events
class FD.StreamView extends Backbone.View

el: $(".stream")

initialize: ->
    # Bind the view to listen for a reset of the collection and rerender
    @collection.on("reset", @render)

    # Listen for a change to this model and run the function getActivities
    FD.filters.on("change", @getActivities)

render: =>
    # render function code

getActivities: =>
    # create a new instance of the FD.Events collection class
    events = new FD.Events

    # create a new instance of this view, passing in the new empty collection
    streamView = new FD.StreamView collection: events, model: FD.filters

    # make an AJAX call and as a part of the callback function, reset the collection
    # for the view we just instantiated above
    params = FD.filters.attributes
    callbackFunc = (responseText) ->
        json = $.xml2json(responseText)
        activities = json.activity
        events.reset activities
    params = FD.filters.attributes
    activities_json = $.get("/landing/Data", params, callbackFunc)  

The problem, as you might see, is that the getActivities function runs double the amount of times each time the collection is called, because the first time it runs it creates a second view and then both of those run. When the collection changes, each of those two instances create two instances, so we have four now, and all four run getActivities. Then 8 and then 16.

Clearly making a new instance of the FD.StreamView class isn’t the right approach, but I don’t know how to reset the collection that the single view is tied to, and how that can then trigger the bound @render function.

Any idea? Please let me know if I’m missing critical information. Thanks in advance.

Michael

  • 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-01T12:53:05+00:00Added an answer on June 1, 2026 at 12:53 pm

    The structure you want is to just bind the view’s render to the collection’s events as you have for reset and maybe add/remove as well depending on the specifics of your application. However, getActivities should simply tell the collection to fetch data via the fetch method, but using the current set of filters (which I assume is a search query). So add an instance property called filters to your collection class, in getActivities do events.filters = FD.filters and then just events.fetch(). When the response arrives the collection will reset, which will fire an event which will cause render() to execute and voila, your view will be up to date. The code you have in render() that is making an ajax request belongs in a collection, not a view.

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
I have a small JavaScript validation script that validates inputs based on Regex. I
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.