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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:24:16+00:00 2026-06-10T23:24:16+00:00

var ContractModel = Backbone.Model.extend({ url: ${g.createLink(controller:’waiverContract’, action:’index’)} }) var contract = new ContractModel({}); contract.fetch();

  • 0
var ContractModel = Backbone.Model.extend({
    url:  "${g.createLink(controller:'waiverContract', action:'index')}"
})

var contract = new ContractModel({});
contract.fetch();
var contracts = new Backbone.Collection.extend({
    model: contract
});

var ContractView = Backbone.View.extend({
    initialize: function(){
        this.render();
    },
    render: function() {
        var root = this.$el;
        _.each(this.model, function(item) {
            var row = '<tr><td>' + item + '</td></tr>';
            root.find('tbody').append(row);
        });
        return this;
    }
});

var cView = new ContractView({ model: contract, el: $('#contracts') });

I have Chrome’s developer tools open. If I do a console.log(this.model) inside of the render function, I can see a mess of an object, of which the two records are stored in .attributes. But instead of two rows being added to the table, I get 7. 6 of which are objects. (Though I see 9 subobjects in Chrome’s console).

Not much of this makes sense to me. Can anyone help me not only get this working, but also understand it? I know that render() fires off as soon as I have instantiated cView, and I know that it’s doing the ajax as soon as I do .fetch() into the model. But that’s the limit of what I can understand in this.

  • 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-10T23:24:18+00:00Added an answer on June 10, 2026 at 11:24 pm

    You should fetch and iterate on the collection, not the model. A model is one “thing” and a collection has many “things”. Assuming you are fetching a JSON formatted array into your model, it will end up with properties like “1”, “2”, and so on, and each of these will just be a normal Javascript object, not a ContractModel instance.

    Here is how you might restructure your code:

    var ContractModel = Backbone.Model.extend();
    var ContractCollection = Backbone.Collection.extend({
      //ContractModel class, not an instance
      model: ContractModel,
      //Set the url property on the collection, not the model
      url:  "${g.createLink(controller:'waiverContract', action:'index')}"
    })
    
    var ContractView = Backbone.View.extend({
      initialize: function(){
        //Bind the collection reset event, gets fired when fetch complets
        this.collection.on('reset', this.render, this);
      },
      render: function() {
        //This finds the tbody element scoped to your view.
        //This assumes you have already added a tbody to the view somehow.
        //You might do this with something like
        //this.$el.html('<table><tbody></tbody></table>');
        var $tbody = this.$('tbody');
        this.collection.each(function(contract) {
          //Add any other contract properties here,
          //as needed, by calling the get() model method
          var row = '<tr><td>' + contract.get('someContractProperty') + '</td></tr>';
    
          //Append the row to the tbody
          $tbody.append(row);
        });
        return this;
      }
    });
    
    //Instantiate collection here, and pass it to the view
    var contracts = new ContractCollection();
    var cView = new ContractView({
      collection: contracts,
      el: $('#contracts')
    });
    //Makes the AJAX call.
    //Triggers reset on success, and causes the view to render.
    //Assumes a JSON response format like:
    // [ { ... }, { ... }, ... ]
    contracts.fetch();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

var JavascriptHelper = Backbone.Model.extend(JavascriptHelper, {}, // never initialized as an instance { myFn: function()
var search= document.getElementById('appMenu').value document.location.href= '${createLink(controller: 'application' , action:'ajaxAppSearch', params: ['query': search])}' The element appMenu
var h=0; var w=0; $(.extend).hover(function() { //alert(h); $(this).css({'z-index' : '999' }); $(this).addClass(hover).filter(:not(:animated)).stop() .animate({ marginTop:
var ref1 = new Firebase(http://gamma.firebase.com/myuser/123,456); ref1.set(123,456); var on1 = ref1.on(value, function(snapshot) { console.log(snapshot.val()); });
var Foo = Foo || {}; Foo.Controller = (function ($) { var $page =
var queueitem = context.CrawlerQueues. Select(cq => new{cq.Guid,cq.Result}). SingleOrDefault(cq => cq.Guid == guid); Is above
var conversations = new Array(); jQuery('.CChatWindow').each(function(){ if (jQuery(this).is(:visible) && jQuery(this).attr(data-conversationid) != 0) { alert(jQuery(this).attr(data-conversationid));
var chart; var d = new Array(); function click() { d = document.getElementById('graph:hi').value; alert(d);
var marker = new google.maps.Marker({ position: myLatlng, map: map, title:Hello World! }); <?php $fd
var pagebacklinks = new Array(); pagebacklinks[jQuery('#somevalue').val()][something] = 33; ERROR I GET ABOVE IS: pagebacklinks[jQuery(#somevalue).val()]

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.