Handlebar Output
Udzielono odpowiedziHi
I'm trying to parse a couple of JSON properties to CSV.
Here's a JSON sample:
{
"data": [
{
"id": 1234,
"codes": [
"AA",
"BB",
"CC"
]
}
]
}
Here's my handlebar code:
id,code
{{#each data.id}}
{{#each codes}}
{{id}},{{codes}}
{{/each}}
{{/each}}
Expected output:
id,code
1234,AA
1234,BB
1234,CC
However, this is what's currently being returned:
id,code
1234,AABBCC
1234,AABBCC
1234,AABBCC
I'm not sure what I'm missing. Is it possible to obtain the expected output?
0
-
Here's the solution, for anyone else wanting to do something similar.
id,code {{#data}} {{#codes}} {{id}},{{.}} {{/codes}} {{/data}}
0Hi Chad Weber, if that template works for you, that's fantastic. If not, I'd like to offer the following as an alternative, which should produce the expected output:
id,code
{{#each data}}
{{#each codes}}
{{../id}},{{this}}
{{/each}}
{{/each}}I hope this helps!
Edit: I've set up an example demo here to view the template in action.
0
Komentarze
Komentarze: 3