Hello,
I have a data collection which is populated in this way:
export function loadAllAirports() {
console.log(allairports)
if (allairports)
return allairports;
var data = webix.ajax().get("http://localhost:8081/data/airports.json");
console.log(data)
allairports = new webix.DataCollection({
data: data.then(data => data.json()).then(data => data.filter(obj => {
if(obj.code == "VIE")
console.log(obj)
if(obj.type!=="Airports"){
return false;
}
return true;
})),
scheme: {
// $init: function (obj) {
// obj.id = obj.code;
// obj.value = obj.name +" ("+ obj.code +")";
// obj.tooltipvalue = obj.name;
// },
$sort:{
by: "code", dir: "asc", as: "string"
}
}
});
return allairports;
}
Then I have a function that populates another object:
export function getComboAirports(){
if (comboairports)
return comboairports;
var data = [];
comboairports = allairports.waitData.then(() => {
var names = [];
if (allairports.data.each){
allairports.data.each(function(obj, index, test){
data.push({id: obj.code, value: obj.name +" ("+ obj.code +")"});
});
}
return data;
});
return comboairports;
}
I want to move the configuration of the objet (id, value … ) into the load function, and in this function simply extract the json object needed for populating combo box.
But if I uncomment the $init function from the load, the obj if this function:
allairports.data.each(function(obj, index, test){
is undefined…
why?