PDA

View Full Version : Array Length in XTemplate



svper
28 Sep 2012, 1:37 AM
Hi,
I'm trying to display something if an array is empty in an Xtemplate.

My code:


'<tr><td class="pendingDocsSignedTableTitle">Signed By:</td></tr>' +
'<tpl if="signedUsers.length == 0">',
'<tr><td class="pendingDocsSignedTableUser">No users signed</td></tr>',
'</tpl>',

'<tpl for="signedusers">',
'<tpl if="xcount &gt; 0">',
'<tr><td class="pendingDocsSignedTableUser">{sn} - {[this.formatFDate(values.d)]} </td></tr>',
'</tpl>',
'</tpl>',


BBUT the


'<tpl if="signedUsers.length == 0">',
'<tr><td class="pendingDocsSignedTableUser">No users signed</td></tr>',
'</tpl>',

part does not seem to work. Anybody have an idea on how to do this ?

redraid
28 Sep 2012, 3:20 AM
This because signedUsers key undefined, check for undefined to:


'<tpl if="values.signedUsers == undefined || values.signedUsers.length == 0">'

demo: http://jsfiddle.net/rJFYS/1/

svper
28 Sep 2012, 3:24 AM
Thanks for the response... but i just found out why it wouldn't work... and i feel like an .

i used signedUsers where signedusers is the right one.

Ty javascript for not throwing decent errors on capitalization :)


Sorry for your time

redraid
28 Sep 2012, 3:56 AM
No problem)
//wbr