javascript - How to inherit and add events in child in backbone.js -


i have tried this solustion couldn't working. situation there parent doesn't have event defined. can not make change in parent. can make changes in child modules need have 2 child modules both adding different event both independent of each other. means if install 1 of child modules event should work, if both installed both events should work.

but doesn't seem work

parent

module.paymentscreenwidget = module.screenwidget.extend({   //it has no event defined  code here....   https://github.com/odoo/odoo/blob/8.0/addons/point_of_sale/static/src/js/screens.js#l997  }); 

module 1

function pos_discount_cards_widgets(instance, module){ //module instance.point_of_sale var qweb = instance.web.qweb; var _t = instance.web._t;  module.paymentscreenwidgetdsicount = module.paymentscreenwidget.extend({       events: function(){         return _.extend({},module.paymentscreenwidget.prototype.events,{             "change .discount-card-select": "selectcard"          });      },      selectcard: function(e){         this.pos_widget.order_widget.update_summary();         this.pos_widget.payment_screen.update_payment_summary();         },   }); 

} //end of code

module 2

function pos_payment_with_decimal(instance, module){ //module instance.point_of_sale var qweb = instance.web.qweb; var _t = instance.web._t;  module.paymentscreenwidgetdecimal = module.paymentscreenwidget.extend({       events: function(){         return _.extend({},module.paymentscreenwidget.prototype.events,{             'keyup': 'keyaction',         });      },       keyaction: function(e) {         var selected = $('.selected .paymentline-input').attr('value');         var re = /[,.]/g;          var str = selected.tostring();         var subst = '';          var result = str.replace(re, subst);         this.$('.selected .paymentline-input').val((result * 0.01).tofixed(2));         },   }); 

} //end of code

it looks asking 2 things, 1 how inherit events in child view, , second how 2 sibling views can have both events active @ same time.

for first part when extending event's hash want access prototype of view extending from. in answer linked called parentview that's because name of view being extended (but there isn't special "parentview" property).

so inherit events can try like

module.paymentscreenwidget = module.basepaymentscreenwidget.extend({      events: _.extend({             "change .discount-card-select": "selectcard"     }, module.basepaymentscreenwidget.prototype.events),     ..rest of view }); 

for second part of question how have both sibling views active @ same time need make sure both referencing same el example passing in reference both of them.

var $paymentform = $('#paymentform'); var discountmodule = new module.paymentscreenwidgetdsicount({el: $paymentform}); var decimalmodule = new module.paymentscreenwidgetdecimal({el: $paymentform});  

Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -