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

The Archive Base Latest Questions

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

I am right now developing a dead simple application using backbonejs mvc javascript library.Just

  • 0

I am right now developing a dead simple application using backbonejs mvc javascript library.Just to show how simple it is here is the html

Sample Html

<div class="container">
    <div>
        <label>
            Name:
            <input id="txtName" type="text" title="Type your name please" /></label>
        <button id="btnSubmit" type="button" value="Submit">
            Submit</button>
    </div>
    <div id="names">
    </div>
</div>

Operation

Here’s all i want the application to do.

  1. User Types a name(or some alphanumeric string) and clicks submit.

  2. The value(which is what they call model i suppose) after validation will be sent to restful service.

  3. Service will return the same string along with status of database save operation.

I am now confused as to where the click event will handled(is it in the model?), after that where should the render method be called?(is it in views). Below you will find the script i had managed up until now

Model.js

//store a global reference to model
    window["model"] = Backbone.Model.extend({

        defaults: { name: "Type your name"
        },
        validate: function () {

        }

    });

View.js

//store a global reference to view
window["view"] = Backbone.View.extend({});

nothing in the view to say 🙁

Application.js

//when every thing is ready kick of the application
$(document).ready(function () {


    var modelInstance = new model();


});
  1. so do i add click event to the button in application.js or model.js.which is the convention/best practice?

  2. Will it be possible for me to render the names collection returned from service into #names and status of the database insertion into another div somewhere up above the container? Can the view render both views?

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

    So, here is a disclaimer: If this is all your app is doing, then Backbone is way too much ceremony. When the app gets more complex with more moving parts, Backbone becomes pretty amazing.

    That being said, I have created a jsFiddle to highlight how you might use Backbone for what you want to do: http://jsfiddle.net/BrianGenisio/CZwnk/4/

    Basically, you have a Person model and a People collection to hold the Person models. You then have three views: NewPersonView which is the form for entering your data, which is responsible for adding new items to the People collection. Then you have a PeopleView view which is responsible for showing People collection, which will watch the collection and show any additions. Finally, is the PersonView which is responsible for showing an individual Person model.

    When it all comes together, it looks a little something like this:

    HTML:

    <script id="new_person_template" type="text/template">    
        <label>
            Name:
            <input id="txtName" type="text" title="Type your name please" />
        </label>
        <button id="btnSubmit" type="button" value="Submit">Submit</button>
    </script>
    
    <script id="person_template" type="text/template">    
        Hello, my name is <%= name %>
    </script>
    
    <div id="container">
    
    </div>
    

    JavaScript

    window.app = {};
    
    window.app.Person = Backbone.Model.extend({
        defaults: { name: "Type your name" },
        validate: function () { }
    });
    
    window.app.People = Backbone.Collection.extend({
        model: window.app.Person
    });
    
    window.app.NewPersonView = Backbone.View.extend({
        template: _.template($("#new_person_template").html()),
        initialize: function () {
            _.bindAll(this, 'submit');
        },
        events:
        {
            "click #btnSubmit": "submit"
        },
        render: function () {
            $(this.el).html(this.template());
            return this;
        },
        submit: function (x, y, z) {
            // If you want this to go up to the server and sync, do this instead:
            // this.model.create({name: $("#txtName").val()});
            // but since we don't really have a server right now, we'll just create and add
            var person = new window.app.Person({name: $("#txtName").val()});
            this.model.add(person);
        }
    });
    
    window.app.PersonView = Backbone.View.extend({
        tagname: "li",
        template: _.template($("#person_template").html()),
        render: function() {
            $(this.el).html(this.template(this.model.toJSON()));
            return this;
        }
    });
    
    window.app.PeopleView = Backbone.View.extend({
        tagName: "ul",
    
        initialize: function() {
            _.bindAll(this, "render", "renderPerson");
            this.model.bind("add", this.renderPerson);
        },
    
        render: function() {
           console.log("rendering");
           this.model.each(this.renderPerson);
           return this;
        },
    
        renderPerson: function(person) {
            var personView = new window.app.PersonView({model: person});
            $(this.el).append(personView.render().el);
        }
    });
    
    
    $(document).ready(function () {
    
        var people = new window.app.People();
        var newPersonView = new window.app.NewPersonView({model: people});
        var peopleView = new window.app.PeopleView({model: people});
    
        $("#container").html(newPersonView.render().el);
        $("#container").append(peopleView.render().el);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now I'm developing the prototype of a web application that aggregates large number
I am new to linq and asp.net mvc and right now i am developing
I am just a beginner in i-phone development and right now i am developing
I'm developing a Java webapp using Spring, Spring Security, Tomcat and MySQL. Right now
Right now I am developing an application that will allow online registration. For development,
I'm a beginner on android.Right now I'm developing a own application for Signature Capture
I'm developing an application right now and I need to disable the quick-search-box as
Right now I'm developing mostly in C/C++, but I wrote some small utilities in
Right now I'm developing a small canvas oriented 2D graphics engine for a game,
Today I'm on an asking spree :P Anyhow... Right now I am developing a

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.