Hi,
I am trying to add the total amount of each nutrients that is in a repeater but can’t seem to get it right. Am starting with energy. I ended up getting this: NaN[object Object]undefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefined[object Object]undefinedundefinedundefinedundefinedundefinedundefinedundefined
Here is the code that I did:
import wixData from ‘wix-data’;
$w.onReady( function () {
$w(“#dataset1”).onReady(() => { let IeSum = 0; let eSum = $w(“#repeater1”).data.reduce(
(accumulator, currentValue) => accumulator + currentValue.energyportion,
IeSum);
$w(“#ESum”).text = eSum.toString()
console.log(“addedEnergy”)
})
})
// and other filter codes below this…
Thank you J.D. and Brodwolfsky. I’ve checked and it wasn’t misspelled. I have also checked the fieldType and it is a number… I am guessing it is because I am filtering my repeater therefore I have that error? Could that be a possibility?
You can also see that the repeater’s data is not taken from the dataset at all, because this is not the format of the IDs in Wix collection (unless you set these IDs using insert() )
NaN stands for not a number and like J. D. and Brod have pointed out, you are not returning a number value in your code, like J. D. says again too with you not having any value for energyportion.
Simply put as J. D. is trying to explain to you, is that you can’t add up numbers in code if you are not receiving any number values to begin with.
Thanks @jonatandor35@givemeawhisky@benibrodi . Based on what you all have said, cos I am filtering the repeater, I think I should be putting the code under the code where I am filtering the repeater instead of in the onReady? This way, there would be a value for the energy portion?
@mydietarystrategies If you connected it via the editor it doesn’t make sense. According to the log you posted, the repeater contains items with ID only. So something is missing.
This is an old thread that is partially irrelevant to your question which makes it hard to follow. I’m closing it.
Please open a new post, describe the issue in details and add your code (if you have code)