//some predifined variables here......
// var ....
//CODE-START....
$w.onReady(async function () {
settingsDATA = await wixData.query(SettingsDB).find()
let dbLength = await settingsDATA.items.length
console.log("DB-Length = ", dbLength)
console.log(settingsDATA.items)
if(dbLength===0) {console.log("if")
save_Settings(0)
}
else{console.log("else")}
})
function save_Settings (choice) {
let toSave
console.log(settingsDATA)
console.log(DropDowns[0])
console.log(DropDowns[1])
console.log(DropDowns[2])
if (choice===0){console.log("SAVE-DATABASE-ID")
toSave = {
"_id": "00001",
"title": "General-Settings",
"setup1": DropDowns[0],
"setup2": DropDowns[1],
"setup3": DropDowns[2],
"setup4": DropDowns[3],
"setup5": DropDowns[4],
}
wixData.save(SettingsDB, toSave)
.then( (results) => {
let item = results;
console.log(results)
} )
.catch((err) => {let errorMsg = err;} );
}
}
When —> “save_Settings(0)” is deactivated…
if(dbLength===0) {console.log("if")
//save_Settings(0)
}
else{console.log("else")}
Everything works fine and i get the expected result.
But when turning-on the “save_Settings(0)”-function, something strange happens.
Then it seems that, the if-query is totaly ignored and the function starts immediately running.
Shouldn’t the length still be = 0 and why no console-log-info anymore —> (“if”)?
Database is at this moment still completely empty (live).
It jumps immediately to “else”, because the save-function does his job first (why ever).
Is this a logical behaviour, or do i have a brain-error?