I have following code:
App.Views.UseCategory = Backbone.View.extend({
template: HandlebarsTemplates['uses/useCategory'],
initialize: function() {
_.bindAll(this, 'render', 'addCategory');
this.render();
},
events: {
'submit #addCategoryForm': 'addCategory'
},
render: function() {
$(this.el).append(this.template(this.options));
return this;
},
addCategory: function(event) {
event.preventDefault();
var self = this;
var useCategoryId = $('select[id=use_category_id]').val();
this.model.set('category_id', parseInt(useCategoryId,10));
this.model.save({ success: console.log('success') });
}
});
Code above works and trigger success callback, so I receive in console “success”.
But why when I change that addCategory function to:
addCategory: function(event) {
event.preventDefault();
var self = this;
var useCategoryId = $('select[id=use_category_id]').val();
this.model.set('category_id', parseInt(useCategoryId,10));
console.log('save?');
this.model.save({ success: this.addedCategory, error: function() { console.error(arguments) } });
},
addedCategory: function() {
console.log('success');
}
success callback is not triggered anymore, why?
Edit:

When you do:
You already call your console log. What you should do is (not the same):
Do you understand the difference or do you need clarifications?
In fact i suspect your
successcallback is never called.EDIT:
model.save(data, opts)takes two arguments. You should do: