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

  • Home
  • SEARCH
  • 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 8891069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:38:41+00:00 2026-06-14T22:38:41+00:00

Just starting to use backbone and have a quick question and thought I’d write

  • 0

Just starting to use backbone and have a quick question and thought I’d write a simple message board. I want to have something that responds to the hash change detail/:id and have added this to the router like this. This seems to work but I don’t think this is the proper way of doing this. Is this, in general, how a http call get an object would take place (specifically the success callback)?

var MessageBoardRouter = Backbone.Router.extend({
  routes: {
    "detail/:id" : "showDetail"//,
  },
  showDetail: function(id){
    console.log('within showDetail with ' + id);
    //var p1=new Post({header:'my original header'});
    var p2=new Post({id:id});
    p2.fetch({
     success: function(){   // <- should I be doing this or different way or is who strategy off???
     console.log(p2.attributes);
     var view= new MbDetail();
     view.render(p2);
    }
    });
 },

thx in advance

  • 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-14T22:38:42+00:00Added an answer on June 14, 2026 at 10:38 pm

    There are 2 ways to respond to backbone events: with a callback (like you have above) or with event bindings. I believe event bindings to be the more idiomatic and “backboney” approach for the general case for the following reasons:

    • events allow multiple places in your code to react to the same event, whereas there can only be a single callback
    • backbone is otherwise designed around events so this approach is consistent and “backboney”
    • the callback style is really only necessary if you want to override the default event dispatch behavior
    • I believe the callback style is inspired by jquery and not as consistent internally within backbone as events

    However, with that in mind, both styles will work just fine. In your specific example, you might want to code it like this:

    var p2=new Post({id:id});
    p2.on('change', function(post){
     console.log(post.attributes);
     var view= new MbDetail();
     view.render(p2);
    }
    p2.fetch();
    

    Some other ancillary points:

    • you don’t necessarily need a new view instance for each fetch, you can create just one, pass the model to it’s constructor, and have it rerender itself on every fetch. This will help avoid memory leaks due to left over event bindings
    • Don’t pass arguments to render(). It’s not designed to expect them. Pass the model to the view via the options.model constructor argument, then reference the model from within render as needed.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am just starting to use UML and have came to the following question:
I have just starting to use excel (to do something other than just open
I am just starting to learn how to use RMI, and I have a
I am just starting Java RMI and have some problems with when to use
I'm just starting to use the TestHelpers in MvcContrib. I want to try and
I'm just starting to use core data in my iphone app. I have created
Just starting to use Ruby on Rails to see what its like. I have
I am just starting to use RabbitMQ and AMQP in general. I have a
I'm just starting to use constants in Ruby. I have module Constants C1 =
I'm just starting to use Eclipse and I feel like I'm missing something in

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.