Concept question in class using webix-jet, functions for class

Hi

Why the function this.buttonVisible work into ready(), but no work into attachEvent?

Thanks in advance.

pseudocode of class :

`
import { JetView, plugins } from “webix-jet”;
export default class LanguagesView extends JetView {
config() {…}
ready() {
this.buttonsVisibles(); //this work
$$(“richselectObj”).attachEvent(“onChange”, function (newv, oldv) {
this.buttonsVisibles(); //this not work, not found function buttonsVisibles
});
}
buttonsVisibles() {
var lang = $$(LanguagesIDS.idSelectLang).getValue();
if (lang == ‘es’) {
$$(LanguagesIDS.btnAddKeyValue).show();
}
else {
$$(LanguagesIDS.btnAddKeyValue).hide();
}
}

Hi,

You should use ES6 arrow function to correctly pass scope into the onChange event handler.

$$("richselectObj").attachEvent("onChange", (newv, oldv) => {
     this.buttonsVisibles(); 
});

With standard function syntax this keyword will point to button view, while with an arrow function this will point to JetView and you will be able to call its methods.

Helga, perfect, Thanks so much!!!