Best Option

Hi,

How to send const locales to function loadData?

sure I’m not doing something right, at the class level, which may be the best option to have the local variable available anywhere. or function loadData into class UsersView?

Thanks in advance

//users.js

import { JetView, plugins } from "webix-jet";

function loadData() {
    
    webix.ajax("/user/getusers?v=" + webix.uid()).then(function (result) {
        
        if (result.json().success) {
            $$(usersIDS.idTable).parse(result.json().response);
        }
        else {
            webix.alert(locales("default_error"), "alert-warning");
        }

    }).fail(function () {
        webix.message(locales("default_error"));
    });
}


export default class UsersView extends JetView {
    
    config() {
        const locales = this.app.getService("locale")._;
        var userGrid ={.....} ;
        return { rows: [userGrid] };
    }

    init(){}
    ready(){
        loadData();
     }        
}

Hello,

Since this.app is available only inside Jet view methods, the locale service can not be accessed in an “outside” function.

The recommended way is to define custom functions as class methods:

ready(){
    this.loadData();
} 
loadData(){
    const locales = this.app.getService("locale")._;
    webix.ajax(...);
}

Hi,

Thank you so much, yes, i try your code and work, but…, in this view i have a grid with a edit button for every row, when click this button open a popup, this popup contain a form, in this form there are a button, then, when i click then button save data in database and call this.loadData(), butn “this” is null, please, how to call loadData() from this button? i get TypeError: this is undefined

How to get a method into the view when is called from button into form into window popup?

Thanks in advance.

pseudo code

export default class UsersView extends JetView {
  
config ()
{
-window (popup)
---form
------button:click:{
--------loadData();
            }

   -grid
      ------------------- editbutton
      ------------------- editbutton
      ------------------- editbutton
}

loadData()(
     webix.ajax(....)
}

}

How do you define the window - as a separate class or else?

If a popup is included into another class, then you can call the event in the popup view to signal that the data should be loaded, and in the init method of the Users view catch this event and call the loadData.

If you are speaking of a button that lies within the same Users view, be sure to use => syntax for click handlers or reference button $scope that points to JetView class where the button is initialized:

view:"button", click:()=>{ this.LoadData() }
//or
view:"button", click:function(){ this.$scope.loadData() }

Thanks Helga!!!