I am trying to render a template in onchange of a input field.
Here is the onchange method.
*.js
_onClickBasketInputChange: function(){
console.log('inside input change',this.basketVerificationId);
var self = this;
var barcode = $('.basket_barcode_input').val();
console.log('barcode',barcode);
// var rec = this._rpc({
return this._rpc({
model: 'mobile.basket.verification',
method: 'get_picking_details',
args: [this.basketVerificationId,barcode],
}).then(function(res){
// console.log('this',self);
console.log('picking_id',res);
var $body = this.$el.filter('.o_barcode_lines');// Here i am getting the error ' Uncaught (in promise) TypeError: this is undefined'
console.log('body',$body);
if (res['status'] == true){
console.log('successs');
var $lines = $(Qweb.render('basketVerificationLines', {
picking:res['picking_id'],
customer:res['partner_id'],
lines:res['line_ids']
}));
$body.prepend($lines);
}
// $('.basket_barcode_input').val('');
var message = res['result'];
if (res['status'] == false){
Dialog.alert(self, message);
}
});
},
But i am getting following error Uncaught (in promise) TypeError: this is undefined
Update:
When change this
to self
, the value of $body
is
body
Object { length: 0, prevObject: {…} }
length: 0 prevObject: Object { 0: div.o_action, length: 1 } And the template not prepend to the body.
Please help to resolve this.
I got the solution,
I replace the .filter
with .find
then it works.
var $body = self.$el.find('.o_barcode_lines');