Skip to content

Instantly share code, notes, and snippets.

@dbarrionuevo
Created January 8, 2015 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbarrionuevo/e17dbca434e977e0ae52 to your computer and use it in GitHub Desktop.
Save dbarrionuevo/e17dbca434e977e0ae52 to your computer and use it in GitHub Desktop.
YouConnect.Behaviors.AddService = Essential.Behavior.extend({
init: function() {
this.category = $('#category_id');
this.addCategoryListener();
},
events: {
'submit': 'addFormListener'
},
addFormListener: function(e) {
e.preventDefault();
$.ajax({
type: 'POST',
url: '',
data: '',
success: function(response) {
// Cómo llamo a this.category acá?
},
error: function(response) {
$.each(response, function(k,v) {
// Cómo llamo a this.category acá?
});
}
});
},
addCategoryListener: function() {
this.category.on("change", function(e) {
// Cómo llamo a this.category acá?
})
},
});
@roperzh
Copy link

roperzh commented Jan 8, 2015

// Opcion 1
addFormListener: function(e) {
  e.preventDefault();
  var _this = this;

  $.ajax({
    type: 'POST',
    url: '',
    data: '',
    success: function(response) {
      // Cómo llamo a this.category acá?
      _this.category;
    },
    error: function(response) {

      $.each(response, function(k, v) {
        // Cómo llamo a this.category acá?
        _this.category;
      });
    }
  });
}

// Opcion 2
addFormListener: function(e) {
  e.preventDefault();

  $.ajax({
    type: 'POST',
    url: '',
    data: '',
    success: function(response) {
      // Cómo llamo a this.category acá?
      this.category;
    }.bind(this),
    error: function(response) {

      $.each(response, function(k, v) {
        // Cómo llamo a this.category acá?
        this.category;
      }.bind(this));
    }.bind(this)
  });
}

@roperzh
Copy link

roperzh commented Jan 8, 2015

events: {
   'submit': 'addFormListener',
  'change #category_id': 'doSomething'
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment