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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:32:24+00:00 2026-06-05T20:32:24+00:00

suppose I have a model and a view ,ths view have two method:one is

  • 0

suppose I have a model and a view ,ths view have two method:one is bind the document mousemove event and the other is unbind method,defalut I give the document mousemove event, once the model’s enable value changed I will call the view’s unbind method:

    window.ConfigModel = Backbone.Model.extend({
        defaults: {
            'enable':0
        },
        initialize: function(){
            this.bind("change:enable", function () {
                var portView2 = new PortView();
                portView2.viewOff();                        
            });
        },
        change:function () {
            this.set('enable', 9);
        }
     })

    window.PortView = Backbone.View.extend({
        viewOn: function () {
            $(document).on('mousemove', function () {
                console.log('move')
            })
        },
        viewOff: function () {
            $(document).off('mousemove');
        }
    })

then I put an input on the document to call the model changed:

    $('input').click(function () {
        var configModel = new ConfigModel();
        configModel.change();
    })

the boot script is :

var portView1 = new PortView();
portView1.viewOn();

The problem is once I call the click the input button ,the chrome would tell me an error:Maximum call stack size exceeded it seems the change be invoke many times.So what’s the problem with my problem ,how can I solve this problem

  • 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-05T20:32:25+00:00Added an answer on June 5, 2026 at 8:32 pm

    Backbone models already have a change method:

    change model.change()

    Manually trigger the "change" event and a "change:attribute" event for each attribute that has changed. If you’ve been passing {silent: true} to the set function in order to aggregate rapid changes to a model, you’ll want to call model.change() when you’re all finished.

    Presumably something inside Backbone is trying to call configModel.change() and getting your version of change which triggers another change() call inside Backbone which runs your change which … until the stack blows up.

    You should use a different name for your change method.


    That said, your code structure is somewhat bizarre. A model listening to events on itself is well and good but a model creating a view is odd:

    initialize: function() {
        this.bind("change:enable", function () {
            var portView2 = new PortView();
            portView2.viewOff();                        
        });
    }
    

    And instantiating a view simply to call a single method and then throw it away is strange as is creating a new model just to trigger an event.

    I think you probably want to have a single ConfigModel instance as part of your application state, say app.config. Then your click handler would talk to that model:

    $('input').click(function () {
        app.config.enable_level_9(); // or whatever your 'change' gets renamed to
    });
    

    Then you’d have some other part of your application (not necessarily a view) that listens for changes to app.config and acts appropriately:

    app.viewOn = function() {
        $(document).on('mousemove', function() {
            console.log('move')
        });
    };
    app.viewOff = function() {
        $(document).off('mousemove');
    };
    app.init = function() {
        app.config = new ConfigModel();
        app.viewOn();
        $('input').click(function () {
            app.config.enable_level_9();
        });
        // ...
    };
    

    And then start the application with a single app.init() call:

    $(function() {
        app.init();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have 2 models. The 2nd model has a one-to-one relationship with the
Regarding this post and this other one . Suppose I have the following: public
Suppose I have a partial view called UserDetails whose @model clause is set to
Suppose I have a view model with a property that looks something like this:
There's no strongly typed View() method to return an ActionResult. So, suppose I have
Suppose I have the view models below. public class CustomerListViewModel { public IEnumerable<CustomerViewModel> Customers
Suppose I have a model Photo with an ImageField . I tried to iterate
suppose you have those model relations: Offer HABTM Category How would you build the
I've been wondering, suppose I have a model with an attribute that in every
Suppose I have class Foo(db.Model): bar = db.ReferenceProperty(Bar) foo = Foo.all().get() Is there a

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.