this.app undefined

JAPJAP
edited September 2018 in Technical questions

Hi,

Is posible get this.app in a custom function in a jevView class?.

I can get this.app in config(), ready() etc. but in customFunc this.app is undefined.

Thanks in advance.

<code>
import { JetView, plugins } from "webix-jet";
export default class SystemView extends JetView {
     config() {
         let myapp = this.app ;  //OK
      }
      ready() {
          let myapp = this.app;  //OK
      }
      customFunc() {
          let myapp = this.app //Undefined
      }
}

Comments

  • this depends on the calling context, to be on a safe side, always call the method through view object

    //will not work
    config(){
         return { view:"button", click:this.customFunc };
    }
    
    //will work
    config(){
         return { view:"button", click:() => this.customFunc() };
    }
    
    //will work as well
    config(){
         return { view:"button", click:this.customFunc.bind(this) };
    }
    
  • ok, thanks!!

  • edited December 2018

    Hello! Struggling with the same issue:

      config() {           
            var toolbar = {
                view: "toolbar",
                elements: [              
                    {},               
                    {
                        view: "richselect", id:"langSelect", labelAlign: "right", width: 100, value: "en", options:
                            [
                                { id: "en", value: "Eng" },
                                { id: "ru", value: "Рус" }
                            ],on: { onchange: this.toggleLanguage.bind(this) }
                    }
                ]
            };       
            return toolbar;  
        };
        toggleLanguage() {  
            webix.delay(() => {
               //this is undefined here        
            })    
        }
    

    Thanks for any help!

  • seems to be defined and is the Jet view as expected https://snippet.webix.com/2ivec9yx

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!