Reputation: 87
While parsing JSON data with a dust.js template, I call a helper and pass an array from the JSON data to the helper as one of its parameters. It's an array of strings like:
"foo": ["a", "b", "c"]
Inside the dust.js helper the value becomes this string: "a, b, c". typeof reports its type as a string. Is there a way to thwart this automatic conversion? I don't want to do a split on the commas, because the individual strings in the array may contain commas.
Upvotes: 2
Views: 1113
Reputation: 136
It depends how you pass in param into a helper. {@myHelpers arrayParam=myArray /}
will be passed in as Array (granted that myArray is an Array) vs {@myHelper arrayParam="{myArray}"/}
will be passed in as a String because of the interpolation. Note how first example does not have {}
around myArray
param.
Here is a working demo of these two examples in JSFiddle.
Upvotes: 2