logo
down
shadow

add a custom method to a backbone model calling server, returning a simple data type


add a custom method to a backbone model calling server, returning a simple data type

By : user2949481
Date : November 17 2020, 01:00 AM
fixed the issue. Will look into that further You are right about not overwriting Backbone.sync. As per the docs:
code :
var myModel = Backbone.Model.extend({
  canDelete: function (parmOne, parmTWo){
    var url = '/url/to/check/if/delete/is/ok/parmOne/ParmTwo';
    return $.ajax({
      async: false,
      type: "GET",
       url: url
    });
  }
});
var myView = = Backbone.View.extend({
  initialize: function (options) {
    ...
  },

  deleteModel: function(event) {
    var that = this;
    this.model.canDelete()
    .done(function (data) {
      // Do some stuff if ok to delete like:
      that.model.destroy();
    })
    .fail(function (data) {
      // Do some stuff if not ok to delete like:
      that.model.notifyError(data.responseText)
    });
  }
});


Share : facebook icon twitter icon
Calling Backbone.Model.Save converts child-Backbone.Model to object?

Calling Backbone.Model.Save converts child-Backbone.Model to object?


By : Chaitanya Dhingra
Date : March 29 2020, 07:55 AM
hope this fix your issue I'm creating a Backbone Model which has a child Backbone Model inside of it: , I think you will need to override parse and toJSON.
code :
  toJSON: function() {
     var json = Backbone.Model.prototype.toJSON.call(this);

     // replace backbone model with json.
     json.video = this.get('video').toJSON();

     return json;
  },

  parse: function(data) {
     // take json of video and set into model.
     this.get('video').set(data.video);
     delete data.video;

     return data;
  },
Backbone: calling a success with a custom sync method

Backbone: calling a success with a custom sync method


By : Dani
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further The first argument to Model.save is a hash of attributes you wish to modify, the options come second and hold the success/error callbacks.
Try
code :
this.model.save({}, {
    success: function() {
        console.log('save success');
    }
});
How do I add a custom method to a backbone model?

How do I add a custom method to a backbone model?


By : Stayforever Withme
Date : March 29 2020, 07:55 AM
this one helps. I've tried: , Any reason not to do the obvious?
code :
Model = Backbone.Model.extend({
  func: function() {
  },
})
Backbone model.save returning error while server sending 200:OK

Backbone model.save returning error while server sending 200:OK


By : l3inadz
Date : March 29 2020, 07:55 AM
should help you out I have defined the following Backbone Model: , You can either use this code dataType: 'text' to fix it
code :
...
this.model.save(myUser, {
    dataType: 'text',
    success: function () {
...
Backbone.js model.isValid() method not returning false for an invalid model

Backbone.js model.isValid() method not returning false for an invalid model


By : abdou hassan
Date : March 29 2020, 07:55 AM
I wish did fix the issue. The problem here is that you're calling the { validate: true } option to your model.set method, then you're subsequently calling model.isValid().
When you call model.set with the validate option set to true, Backbone.js will not set the properties you pass unless they all pass validation. So, by the time you call model.isValid() the model has been changed back to the previous version (before the .set call). model.isValid() automatically calls the model.validate() method and passes the current attributes of the model to it.
shadow
Privacy Policy - Terms - Contact Us © ourworld-yourmove.org