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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:51:26+00:00 2026-06-15T13:51:26+00:00

Using Backbone i’m starting to build an App where i have everything cleanly separated.

  • 0

Using Backbone i’m starting to build an App where i have everything cleanly separated. But now i have the following question. Where should i put the App main logic, in the views or in the model.
For example i have a view and a model, which are binded to a button and when i click that button i have to make

$.ajax(params)  

do i put that in the view or the view calls a method with :

this.model.doAction(params) 

which do you think is the best approach?

  • 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-15T13:51:27+00:00Added an answer on June 15, 2026 at 1:51 pm

    You can define an events property in the view which is of the format {"event selector": "callback"} for eg. {"click .collapse": "collapse"} where collapse would be a function defined as a property of the view. Then write your ajax request code in this callback function.

    Also, unless I am missing something, “binding a view and model to a button” doesn’t sound correct Backbone way to me. Instead you should think of one instance of model associated with one instance of the view. Whenever an attribute of the the model instance changes, a model change event will be triggered. You can bind a view function to this event so that change in the model is reflected in the view. Here is a quick example

    var Book = Backbone.Model.extend({
       // ...
    });
    
    var BookView = Backbone.View.extend({
    
        initialize: function () {
            this.model.bind('change', this.render, this);
        },
    
        render: function () {
            // here, make changes to the dom as per changes in model
        }
    });
    

    To associate a model with a view instance, you can pass the it while instantiating a new
    view object..

    var book = new Book({
       title: "A great book"       
    });
    
    var view = new BookView({model: book});
    
    view.model.set('author', 'AGreatAuthor');
    

    The set function call will fire change event and will result in render function of view
    to be called.

    Refer to the annotated source of Todos app example for a complete example.

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

Sidebar

Related Questions

I'm using backbone for an app that I'm building. In this app, I have
I'm building a backbone app using backbone-relational models (but that shouldn't matter for this
I am using backbone to build my web app. Currently I am facing an
I am using backbone.js here is my scenario Lets say I have a view
I have been using Backbone.js to act as a middleman between Wordpress (using the
I am using backbone.js, and trying to fetch some json from twitter, but it
I'm trying to keep track of the state in this app using Backbone.js: I
I have a collection ( using the Backbone.paginator ) that fetchs a array of
I am using backbone.js and underscore.js to build an javascript application. Since hours of
I have been using Backbone a lot lately and love it because it keeps

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.