Hi
I’ve written my backend code which is working fine as i can see the correct values in the consol log on my form.
what i cannot figure out is how do i get the values of the consol log into my elements on my form? (element names as below) this is how i thought my front end should look but it errors says item undefined
FRONT END
import wixData from ‘wix-data’;
import {populateNutrients} from ‘public/new-file.js’
$w.onReady( function () {
populateNutrients(“MyFoods”,“Banana (Large)”)
$w(’ #protein1Text ‘).text = item.protein.toString();
$w(’ #carbohydrate1Text ‘).text = item.carbs.toString();
$w(’ #fat1Text ‘).text = item.fat.toString();
$w(’ #calories1Text ').text = item.calories.toString();
});
BACKEND
import wixData from ‘wix-data’;
export function populateNutrients (collectionName,valueField) {
wixData.query(collectionName)
.eq(“foodType”,valueField)
.find()
.then( (results) => {
let items = results.items;
let item = items[0];
let measurement = item.measurement;
let protein = item.protein
let carbohydrates = item.carbs
let fat = item.fat;
let calories = item.calories;
console.log(measurement,protein,carbohydrates,fat,calories)
} )
. catch ( (err) => {
let errorMsg = err;
console.log(errorMsg);
})
}