framework7

Open full view…

Template condition not false for empty array

ErikCornelisse
Sat, 29 Nov 2014 11:37:52 GMT

I am not sure if this is a bug or a feature request. In case an array is empty ` myArray = []` the template condition `{{#if myArray}}` will be considered as true. The documentation is correct on this matter because myArray is not false nor undefined, null, "", or 0. However empty arrays don't have anything to display and therefore I think it might be a useful addition to consider empty arrays as false. Apologies in advance if this matter has been raised or solved already.

ErikCornelisse
Sat, 29 Nov 2014 13:05:10 GMT

Sorry to bother but you can skip this request. I found a very simple solution `{{#if myArray.length}}` (I tried this before but due to a mistake on my side it failed)

Vladimir Kharlampidi
Sun, 30 Nov 2014 09:36:10 GMT

Yep, that is the correct solution to just check "length" property