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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:05:17+00:00 2026-06-17T09:05:17+00:00

I am working with backbone.js and i am trying to understand if i am

  • 0

I am working with backbone.js and i am trying to understand if i am doing something wrong or is this how backbone should behave.

i am building a table, for that i have 2 templates
the first one is all the container and <thead> information which are irrelevant for the question.

then i am rendering the collection of items into rows. with this view:

   MYAPP.Menu.ItemView = Backbone.View.extend({
    tagName: 'tr',      
    template: template('menu-item'),
    initialize : function(modelItem) {
    this.model = modelItem;
    this.model.on('all', this.render, this);
    },
    render : function() {
        var html = this.template(this.model.toJSON());
        this.$el.html(html);
        return this;
    }
});

this is the template for menu-item:

  <script type="text/x-mustache-template" id="menu-item-template">
            <td>{{title}}</td>
            <td>{{description}}</td>
            <td>{{price}}</td>
            <td>{{status}}</td>
            <td></td>
    </script>

the output that i am getting inside the <tbody> tag is this:

     <tr id="1" title="title1" price="price1">
            <td>title1</td>
            <td></td>
            <td>price1</td>
            <td></td>
            <td></td>
    </tr>

and so on.
SO HERE COMES THE QUESTION

Why is all the data stored inside the <tr> tag as attributes? i don’t want that. why is it there?

Thanks.

  • 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-17T09:05:18+00:00Added an answer on June 17, 2026 at 9:05 am

    You’re most likely initializing your view like this:

    new MYAPP.Menu.ItemView(someModel);
    

    This is incorrect, the correct way is to pass a model in an options object using the key model:

    new MYAPP.Menu.ItemView({model:someModel});
    

    The fact that the model attributes are being set as the element’s attributes is just a bit of a unlucky coincidence in naming. Internally Backbone.Model stores its values in a property called attributes. Backbone.View on the other hand accepts an option called attributes in the options argument, and copies that over to View.attributes, which in turn sets those as attributes on the root element.

    There are some special properties which are copied to the view automatically: id, cssClass, el, model and collection, just to name a few. Because a model is just an object, calling new View(model) is equivalent to new View({id:id, attributes:attributes, ...}), and that causes the curious effect you’re seeing.

    So looking at your constructor code, it should look like this:

    initialize : function(options) {
       this.model = options.model;
       this.model.on('all', this.render, this);
    }
    

    But because Backbone takes care of setting some of the View’s options for your, including model, you don’t strictly speaking even need to set this.model:

    initialize : function(options) {
       this.model.on('all', this.render, this);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a working coffeescript/backbone idiom that looks like this: SidebarWidgets = ((() ->
i am trying to understand Backbone.js and how it works. i have created two
I'm very new to Backbone.js and am trying to get this simple example working.
I'm working with backbone and lazy-loading both templates and data for one of my
I'm working on a backbone.js project and I'm calling my github repo. I have
I'm working with backbone+requirejs+jquery and I have a problem with jquery plugin loading in
I am working on a research project that deals with social networks. I have
I'm trying to play around with a backbone app that was made with an
I am trying to make a text thinner and i have seen it working
I'm working on a backbone rails application that needs to poll the server to

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.