QML Array Undefined Check

I get an undefined array error in QML and wonder what to fix this error. Here is the current code:

opacity: mBitField[index] 

every time and after a while, it cannot assign undefined to opacity , and I wonder if this fix is ​​really:

 opacity: mBitField[index] == "undefined" ? 0 : mBitField[index] 

Basically what I'm trying to say is an undefined array to assign 0 opacity otherwise assign whats in the array.

+4
source share
1 answer

Your code converts the array element to a string that is not needed. To check only undefined, it would be:

 opacity: mBitField[index] === undefined ? 0 : mBitField[index] 

Or if the difference between undefined and null (and false, 0 or "") is not important, just use Javascript :)

 opacity: mBitField[index] || 0 
+6
source

All Articles