Model Datacollection and Function waitData

Hello,

in the student sample on github there is the student.js model like this:

export const students = new webix.DataCollection({
	url:"data/students.json"
});

// for bullet and radar
export function getGrades(id){
	return webix.copy(students.getItem(id).grades);
}

//for average-individual chart
export function getStats(id){
	const student = students.getItem(id);
	return {
		stats:student.months,
		name:student.name
	};
}

I want to use in a view only let’s say the function getGrades().
How can I be sure, that the Datacollection is already loaded, when using the function (in my case, the Datacollection is not a json file, but a big rest-request).

Where do I need to put the “waitData”-option or a promise.
The function fills in my case a combobox.

Thanks,
Martin

if you just want to know if data loaded or not then this scenario is possible

export const students = new webix.DataCollection({
    url:"data/students.json",
    on: {
       onBeforeLoad: function() {
            this.$isLoaded = false;
       },
       onAfterLoad: function() {
            this.$isLoaded = true;
       }
    }
});

check:
if(students.$isLoaded){...}

but would be better if you make app logic asynchronous

Thanks, Integral.
Unfortunetely I need not only to know if the data is loaded, but I need to wait until it’s finished.
How would a async logic look like in that sample?

Thanks again!
Martin

export const students = new webix.DataCollection({
    url:"data/students.json"
});

// for bullet and radar
export function getGrades(id){
    return students.waitData.then(() => webix.copy(students.getItem(id).grades)); 
}

//for average-individual chart
export function getStats(id){
    return students.waitData.then(() => {
        const student = students.getItem(id);
        return {
            stats:student.months,
            name:student.name
       };
    })
}