cordova - Javascript closure: Phonegap and 'this' in callback -
this question has reply here:
how access right `this` / context within callback? 4 answersi somehow need pass reference current object in callback phonegap's notification plugin. i'm pretty sure involves closures can't quite work out.
here's code:
export default ember.arraycontroller.extend({ ... delete: function(buttonindex) { if (buttonindex === 1) { // how access 'this' here? 'self' doesn't work here either. console.log('deleting survey id=' + this.get('obj_to_delete')); } }, actions: { deleteaction: function(obj_id) { var self = this; this.set('obj_to_delete', obj_id); this.store.find('survey', obj_id).then(function(survey) { navigator.notification.confirm( 'are sure want delete?', self.delete, // need sort of closure binding self here? 'confirm delete', ['yes', 'no'] ); } ); } } });
how can reference 'this' in delete method?
try:
navigator.notification.confirm( 'are sure want delete?', self.delete.bind(self), // need sort of closure binding self here? 'confirm delete', ['yes', 'no'] );
in line "self.delete.bind(self)", bind function "this.delete".
javascript cordova
No comments:
Post a Comment