var ListView = Backbone.View.extend({
el: $('hello'),
initialize: function() {
var stuff = new FieldCollection();
var output;
stuff.parse();
stuff.fetch({
success: function (collection, response) {
console.log(response);
output=response;
return response;
}
});
this.render(output);
},
render:function(output){
console.log(output);
$(this.el).append("<button id='add'>hiii</button>");
$(this.el).append("<button id='removeAll'>Remove all list item</button>");
}
});
Here I am trying to catch the value of the response in output variable… but it’s coming up ‘undefined’. Any ideas where I’m mistaken?
The
fetchmethod is asynchronous, so theoutputvariable won’t have been assigned by the time you use it. Try putting therendercall inside the success-callback instead: