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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:25:14+00:00 2026-06-10T05:25:14+00:00

Below is my backbone view. define([ ‘app’, ‘backbone’, ‘twig’, ‘templates/report’, ‘data/reportViewCollection’, ‘data/reportViewModel’ ], function

  • 0

Below is my backbone view.

define([
    'app',
    'backbone',
    'twig',
    'templates/report',
    'data/reportViewCollection',
    'data/reportViewModel'
], function (app, Backbone, Twig, template, Collection, Model) {

    var collection = new Collection();
    var fetching;

    return Backbone.View.extend({
        setParams: function (rlId, viewId, categoryId, depth) {
            // reset any possible pending previous repests.
            fetching = false;

            var model = collection.getModel(rlId, viewId, categoryId, depth);
            if (!model) {
                model = new Model({
                    rlId: rlId,
                    viewId: viewId,
                    categoryId: categoryId,
                    depth: depth
                });
                fetching = model.fetch({
                    success: function (model) {
                        collection.add(model);
                    },
                    error: function (model) {
                        alert('error getting report view');
                    }
                });
            }
            this.model = model;
        },
        render: function () {
            var that = this;
            var done = function() {
                app.vent.trigger('domchange:title', that.model.get('title'));
                that.$el.html(Twig.render(template, that.model.toJSON()));

                that.delegateEvents(that.events);
                fetching = false;
            };
            if (fetching) {
                app.loading(this);
                fetching.done(done);
            } else {
                done();
            }
            return this;
        },
        events: {
            'change select.view-select': 'viewSelect',
            'click #dothing': function (e) {e.preventDefault(); alert('hi');}
        },
        viewSelect: function(e) {
            var selectedView = $(e.target).val();
            var rlId = this.model.get('rlId');
            if (!rlId) rlId = 0;
            var url = 'report/' + rlId + '/' + selectedView;
            console.log(this, e, url);
            Backbone.history.navigate(url, {trigger: true});
        }
    });
});

Description of functionality:

What happens is when a specific url is navigated to, the setParams() function is called to fetch the model from the server. When the render method is called, it checks if we are currently fetching the model and if so, uses sets a deferred callback to render the template when it gets done fetching. When the model is fetch-ed and we are ready to render, renders the template and fills in the view by that.$el.html().

Problem:

What happens is that my events work perfectly the first time I navigate to a url, but when I hit the back button, my events don’t get attached.

I’ve stepped through the code and can’t see any differences. The only real difference is that I’m loading the model from the cached collection immediately instead of doing an ajax request to fetch it.

Any clues what is going on?

  • 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-10T05:25:16+00:00Added an answer on June 10, 2026 at 5:25 am

    I resolved my issue. The comment by @mu set me in the right direction.

    I am using Marionette and my view is contained in a region. In the Region’s open function, it is doing this.$el.html(view.el); which wipes out the events in certain circumstances. I’m still not sure why it does in some but on in others.

    The Solution proved to be to add an onShow function to my view that call’s this.delegateEvents(). Everything is working smoothly now!

    I eventually figured it out by stepping through the code and watching the events registered on the view’s div.

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

Sidebar

Related Questions

My class is defined as below: class NewUser extends Backbone.View template : JST[backbone/templates/events/new] events
I'm working on converting a single-page app to backbone.JS. The View below uses the
Given the backbone view function below, what is the correct way of passing this
App.Views.VideoView = Backbone.View.extend({ initialize: function() { _.bindAll(this, 'render'); this.model = this.options.model; this.render(); }, render:
I have a standard list view setup with backbone that looks something like below.
Take a look at this jsFiddle Code also listed below: window.MyView = Backbone.View.extend({ ticks:
Using Backbone I can fetch the Collection like below and render a Backbone View
Hi. I am trying to call dust template from a backbone view in rails
I have the backbone.js view below: class MyApplication.Views.Cake extends Backbone.View tagName: 'li' className: 'cake'
My view is set up as below. simple. var ItemView = Backbone.View.extend({ tagName :

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.