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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:28:13+00:00 2026-05-26T01:28:13+00:00

I am building a simple mapping application that shows routes from each airport, which

  • 0

I am building a simple mapping application that shows routes from each airport, which includes the following models:

  • Airport (code, like JFK, lat/lng and city name)
  • Route (ex: JFK to SFO, LGA to YYZ, etc.)

I am able to retrieve the routes from each airport from my backend service like so, and then render each route as a part of a list and eventually add them to the map:

RoutesView = Backbone.View.extend({
    el: $("body"),
    // template: Handlebars.compile($("#routes-template").html()),
    events: {
        "click #update": "getRoutes",
        "click #submit-button": "getRoutes"
    },
    initialize: function() {
        console.log("Initializing RoutesView");
        this.input = $("#airport-code");
        this.collection = new Routes; 
        this.collection.bind("reset", this.render, this);
        this.collection.bind("add", this.addOne, this);
        this.collection.bind('all', this.render, this);
        // this.collection.fetch({ data: jQuery.param({airport_code: this.input.val()}) });
        // this.routes = new Routes;
        // this.routes.bind('add',   this.addOne, this);
        // this.routes.bind('reset', this.addAll, this);
    },
    getRoutes: function() {
        console.log("fetching new routes getRoutes()");

        // this.routes.fetch({ data: jQuery.param({airport_code: this.input}) });
        this.collection.fetch({ data: jQuery.param({airport_code: this.input.val()}) });

    },
    addOne: function(route) {
        console.log(route);
        // console.log("adding one route...");
        var view = new RouteView({model: route});
        view.render();
    },
    render: function() {
        $("#map-container").gmap3({ action: 'addMarker', address: this.input.val(), map: {center: true, zoom: 7 }, marker:{ options:{ draggable: false  } } });
        $(".helptext").remove();
        $("#airport-headline").text("Flights from " + this.input.val());
    }
});

RouteView = Backbone.View.extend({
    tagName:  "div",
    template: Handlebars.compile($("#route-template").html()),
    events: {
        "click .more"              : "showMore",
    },

    showMore: function() {
        var routeid = this.model.get('id');
        console.log("Showing more info for route id #" + routeid);
        // this.model.toggle();
    },
    render: function() {
        console.log("Rendering route...");
        $("#map-container").gmap3({ action: 'addMarker', address: this.model.get("source_airport"), map: {center: true, zoom: 7 }, marker:{ options:{ draggable: false  } } });
        $("#routes").append("<div>hi</div>");
        return this;
    }
});

I see that the routes collection does get initialized, but Where would I loop through it and render the corresponding RouteView for each route?

  • 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-26T01:28:13+00:00Added an answer on May 26, 2026 at 1:28 am

    The logical place is after fetching the Routes data from the server.

    You have two options:

    • Have a RoutesView, one view that shows the entire Routes collection.
    • Have a RouteView for each element in the Routes collection

    The first is more efficient, especially if you have many routes in your collection. And it is good to use if you load the collection of routes, display it, and then on a new search you load another collection and display it.

    The second approach is more useful if, after displaying the collection, the user can interact with it. Then on each view instance, you can have an event listener (ex for click or mouseover events), while in the ‘one view’ approach you get only one global listener and you have to figure out on which of the Routes it happened.

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

Sidebar

Related Questions

I am building a simple application which is in charge of collecting Office files
I`m building simple app which shows information about most car brands. I have rootViewController
I'm building simple application for myself in JSP which stores URL for me and
Building simple code (example is below) returns error on eclipse, while g++ from commandline
I'm building a simple Todo List application where I want to be able to
I am building a simple Django app that will use scribd to display documents.
I'm building a simple ASP.NET web application in VS 2008 with a SQL 2005
I'm building a simple java Servlet which passes categories using a URL variable into
I'm building a simple web based forum application. I want to allow users to
I'm building simple dictionary application using WPF. I'm using MVVM pattern, databinding and FlowDocument

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.