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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:37:47+00:00 2026-06-05T18:37:47+00:00

My code work in three step: I fetch a collection with a structure. I

  • 0

My code work in three step:

  • I fetch a collection with a structure.
  • I populate the collection.
  • I render the collection with collectionView.

When i render the collection with cssElementListView,

  • if i let alert(“toto”), it render me properly all the collection.
  • If not, it just render me [Object object].

What’s wrong ?

 /************************************ Collection *******************************/

var cssElementList = Backbone.Collection.extend({
//on permet de charger different model de donnée
    initialize: function(props) {
        var self=this;

    // binding definition
        _.bindAll(this, "populate");
        this.bind('reset', this.populate);

        // get value from props
        this.url=(props.url==undefined)? "model.json" : props.url;
        this.elem=(props.elem==undefined)? "#age" : props.elem;
        this.model=(props.model==undefined)? cssElement : props.model;
        this.meta("result", "false");

    //fetch with url JSON file
        this.fetch();
    },

    populate: function(){
        var self=this;
        this.each(function(model){
            var mid=model.get('id');
            var mavaleur=$(self.elem).css(mid);
            model.set("value",mavaleur);
        });
    },
});

/************************************ CollectionView *******************************/
//Collection View
var cssElementListView = Backbone.View.extend({
    initialize: function() {
        _.bindAll(this, 'render');
        this.render();
    },
    render: function(){
        var self=this;
        //TROUBLE IS HERE
        alert("toto");
        this.collection.each(function(model){
            var view = new cssElementView({ el: this.el, model: model });
            $(this.el).append(view.render());
        },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-05T18:37:49+00:00Added an answer on June 5, 2026 at 6:37 pm

    I suspect it is a problem with the asynchronous nature of fetch(). your call to alert gives it enough time to finish fetching the data from the server, but if you don’t make the call, the collection is still empty when you try to render because the ajax for fetch hasn’t returned from the server and called its success callback yet. (you can read through the code here, around line 758.)

    You would be better off binding your render to a reset event (or other event) rather than rendering immediately when you initialize your view, like so:

    // in cssElementListView.initialize 
    this.collection.on('reset', this.render, this);    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've had soooo much trouble getting this code to work properly!!!! It runs fine
Is there a way to make this code work? LogonControl.java @Audit(AuditType.LOGON) public void login(String
MyClass c = 10; Is there any way to make this code work? I
I'm having an issue getting some code to work. Is there a way to
Are there any guidelines to writing Google App Engine Python code that would work
Is there any way I could run the following 'logical code' to actually work?
There is a weird code here that I need to make work.. can you
The following code work well on ICS and not on 2.3.3. I use a
In simulator my gps code work fine. But when I install my app in
The media player embedded code work only in IE.How I can do it able

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.