Sorry, if this is basic but I'm a total starter with Backbone.js and I can't work out how to simply assign an attribute (data) with data obtained from fetch. I believe it's to do with binding (this), but I can't figure it out. Here's my code:
var form_model = Backbone.Model.extend({
urlRoot: QuoteForm.ajaxurl,
data: "",
initialize: function()
{
this.fetch({
data: { action: 'quote_form_data' },
success: function (response) {
// this bit won't assign
this.data = response.toJSON();
}
});
}
});
When I console.log() the returned data it is correct, however I cannot assign it and use the data attribute in my view. Please help.