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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:22:31+00:00 2026-06-11T03:22:31+00:00

How do I pass the name variable from the router to the FriendInfocollection? Anytime

  • 0

How do I pass the name variable from the router to the FriendInfocollection? Anytime I browse to localhost/app/person/MyName console.log returns a 404 for localhost/slim/index.php/person/

Can someone point me in the right direction on sharing this variable with the collection so it uses the correct url?

<!DOCTYPE html>
<html>
<head>
    <title>I have a back bone</title>
</head>
<body>
    <button id="add-friend">Add Friend</button>
    <button id='view-friends'>View Friends</button>
    <ul id="friends-list">
    </ul>
    <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.3/underscore-min.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.2/backbone-min.js"></script>
<script>
Friend = Backbone.Model.extend({
    name: null,
    age: null,
});
FriendDetailModel = Backbone.Model.extend();
FriendInfoModel = Backbone.Model.extend({
    name: null 
});
FriendDetailCollection = Backbone.Collection.extend({
    url: '../slim/index.php/people/',
    model: FriendDetailModel

});
FriendInfoCollection = Backbone.Collection.extend({
    model: FriendInfoModel,
    url: '../slim/index.php/person/' + name,
});


Friends = Backbone.Collection.extend({
    initialize: function(models, options) {
        this.bind("add",options.view.addFriendLi);
    }
});
AppView = Backbone.View.extend({
    el: $("body"),
    initialize: function() {
        this.friends= new Friends(null, {view:this});
    },
    events: {
        "click #add-friend":  "showPrompt",
    },
    showPrompt: function () {
        var friend_name = prompt("Who is your friend?");
        var friend_age = prompt("What is your friends age?");
        var friend_model = new Friend({name: friend_name, age: friend_age});

        this.friends.add(friend_model);
    },
    addFriendLi: function(model) {
        $("#friends-list").append("<li>" + model.get('name') + " " + model.get('age') + "</li>");
    }
});
var appview = new AppView;
var people = new FriendDetailCollection;
var person = new FriendInfoCollection({name:'Sean'});

FriendView = Backbone.View.extend({
    el: $("body"),
    initialize: function() {
        _.bindAll(this,'render');
        this.collection.bind('reset', this.render);
    },
    events: {
        "click #view-friends": "fetch_list",
    },
    render: function() {

        var results = this.collection.toJSON();
        $.each(results, function(key, value) {
            var msg = results[key]['firstname'] + " " + results[key]['lastname'];
            console.log(msg);
        });
    },
    fetch_list: function() {
                people.fetch({
                        success: function(data) {
                                //console.log("success");
                        }
                });

    }

});

FriendInfoView =  Backbone.View.extend({
        el: $("body"),
        initialize: function(name) {
                _.bindAll(this,'render');
                this.collection.bind('reset', this.render);
        },
        render: function(name) {
                var results = this.collection.toJSON();
                $.each(results, function(key, value) {
                        var msg = results[key]['firstname'] + " " + results[key]['lastname'];
                        console.log(msg);
                });
        }

});


friendview = new FriendView({collection: people});
friendinfoview = new FriendInfoView({collection: person});
AppRouter = Backbone.Router.extend({
    routes: {
        "friends":"people",
        "person/:name":"personDetail"
    },

    people: function() {
        console.log('all the people');
        people.fetch({
            success: function(data) {
                //console.log("success");
            }
        });

    },

    personDetail: function(name) {
        person.fetch({
                        success: function(data) {
                                console.log("success");
                        }
                });

        console.log('one person named ' + name);
    }
});
var approuter = new AppRouter;
Backbone.history.start();
</script>
</body>
</html>
  • 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-11T03:22:33+00:00Added an answer on June 11, 2026 at 3:22 am

    You should define routers like this :

    var AppRouter = Backbone.Router.extend({
        routes: {
            'name/:name'                : 'getPerson'
        },
    getPerson: function(name) {
        var callperson = new Person.Details({
            name        :   name
        });
    }
    

    Instantiate routes when dom ready

        app_router = new AppRouter;
    

    Now you can access the name like this on your view:

        this.options.name
    

    But you must define the options variable inside the initialize functions

        initialize: function ( options )
    

    And for sure you can set the model like this :

        model.set('name', name)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to pass the coloumn name also like a variable.Please edit this
I know to access scripts from another module, you just pass the module name
I have to pass a HWND variable from the main program to a function
the problem i am face right now is i can't pass a variable from
How do you pass a variable from jQuery to PHP without a page refresh?
New to SPA MVC4, trying to pass a session variable to LinqToEntitiesDataController from the
How can I pass a variable to a cfm page that I'm including from
i have one table TABLE_SUBJECT And i pass subject name to DBHelper.java. Then i
How can I pass a functions name to a function and then call it?
I'm having trouble understanding the workings of Javascript...I want to pass a form name

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.