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);
}
});