Status: New
Owner: ----
Labels: Type-Defect Priority-Medium
New issue 23 by b.l.stein: String treated as array (JavaScript version)
http://code.google.com/p/json-template/issues/detail?id=23
Given the following template fragment
{.section term}
{.repeated section @}
<li>{...@}</li>
{.or}
<li>{...@}</li>
{.end}
{.end}
The following input works as expected:
{term: ['one', 'two', 'three'] }
The following input however does not:
{term: 'one'}
On Firefox the string is treated as an array and returns a list element for
each character. On Internet Explorer it throws an error. The expected
result would have been to call the {.or} section of the template and only
produce a single list element.
The problem occurs on line 276 of json-template.js (210 2009-04-30), where
the code assumes that if the object exists and has a length value greater
than zero it will repeat the section:
if (items && items.length > 0)
Changing this line to test for the presence of an array fixes the error and
produces the expected result. The resulting fix is as follows:
if (items && Object.prototype.toString.apply(items) === '[object Array]'
&& items.length > 0)
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "JSON
Template" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/json-template?hl=en
-~----------~----~----~----~------~----~------~--~---