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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:38:42+00:00 2026-05-31T06:38:42+00:00

I hope you are all well! A question for an app that uses Backbone.js

  • 0

I hope you are all well!

A question for an app that uses Backbone.js and node.js.
I’m in a situation where I want to create a model, and then automatically go to a different uri that is constructed using the newly created model :

MessageView = Backbone.View.extend({
  events : {
    'click #button' : 'go here'
  }
  go here : function(model) {
    var message = new Message({model : model)};
    var id = message.get('id');
    // go to uri '/messages/id'

Now I have set up my app using Express, and so I would like to have a real GET request to the server here invoking the data from the newly created model. So I would like to load the page and not just change the view.
One way to do this (I think) would be to just have

window.location = 'messages/'+id;

as the last line above, but I seem to have the impression this is not good practice for Backbone in general.
Otherwise, could just create the message model inside of the render method, and then write its id directly into the href of the button when the view is rendered, but this also seems messy :

render : function() {
  var message = new Message({model : model)};
  var id = message.get('id');
  $('a #button').attr('href', '/messages/'+id);
}

Any ideas on how I could set this up in a more elegant way? Thanks 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-05-31T06:38:43+00:00Added an answer on May 31, 2026 at 6:38 am

    Are you sure you want to actually change the browser page to a new window location? Doing that will cause all your javascript and everything else to have to reload. if you need to invoke a GET to the server to get the information for that model id, you just need to call fetch on a model with an id attribute.

    From the little code you have here, this may be more along the lines of what you’re trying to do:

    MessageView = Backbone.View.extend({
      events : {
         'click #button' : 'go_here'
      },
    
      go_here : function(model) {
         //myID is the id of your message you want to get from the server
         //I'll leave it up to you on how you get the id of what you 
         //want from that button
    
         //I'll also assume that you have a router setup somewhere
         //to handle navigation
         MyApp.MyRouter.navigate("messages/"+id, {trigger: true});
      }
    });
    

    Then, in your router you’d have a route setup to watch for that:

    routes: {
        "messages/:id" : "showMessage"
    }
    

    And in your showMessage function:

    showMessage: function(id) {
        var message = new Message({id: id});
        message.fetch({success: function(model) {
            //render view of for the message to be shown
            var messageView = new MessageView({model: model});
            messageView.render();
        });
    }
    

    When you create the view this way, it will be created with a model that already has all the data for your message in its attributes.

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

Sidebar

Related Questions

hope all of you doing well. I have small question in C#.Net. actually i
Well I hope this question fits to Stackoverflow ( if otherwise, I want to
i hope this is a simple question! in the following code all is well
hope all is well. I am using Version 7.0. This morning I was struggling
Hope you're having a good Friday and stuff... okay, so here's my question: All
Hope you are well. I'm trying to create a mass folder creator using Excel
I hope the title is chosen well enough to ask this question. Feel free
Just a quick question, that I cannot fathom out, hope you guys and girls
I have a web app that users upload files to. I want to authenticate
I've prototyped an iPhone app that uses (internally) SQLite as its data base. 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.