How do I trigger the success callback on a model.save()?

前端 未结 8 998
粉色の甜心
粉色の甜心 2020-11-28 23:06
this.model.save({
  success: function(model, response){
    console.log(\'success\');
  },
  error: function(){
    console.log(\'error\');
  }
})

相关标签:
8条回答
  • 2020-11-28 23:48

    You may use underscore lib as follows as backbone already depends upon this. Remember first argument of save must either have attributes or you may just pass {} in case you want to save model itself.

    this.model.save({}, _.bind(function(model, response){
      //Do whatever you want e.g.
      this.collection.add(model)
    }, this))
    
    0 讨论(0)
  • 2020-11-28 23:50

    The first argument of save is the attributes to save on the model:

    this.model.save( {att1 : "value"}, {success :handler1, error: handler2});
    
    0 讨论(0)
提交回复
热议问题