1

I've a json that's being created from a CSV that looks like this,

[["Year","Make","Model","Description","Price"],["1997","Ford","E350","ac, abs, moon","3000.00"],["1999","Chevy","Venture \"Extended Edition\"","","4900.00"],["1999","Chevy","Venture \"Extended Edition, Very Large\"","","5000.00"],["1996","Jeep","Grand Cherokee","MUST SELL!\nair, moon roof, loaded","4799.00"]] 

I need to use this in template using Handlebars.js, I know when to use this when the json was like this

[{"data" : "data1"},{.....}] 

but doesn't know how to use handlebars when the json looks like the one I've been given at the begning, when I tried the following code,

        {{#each this}}
        <li>{{0}}</li>
        {{/each}}

I get the following error at the console

Uncaught Error: Parse error on line 3:
...}            <li>{{0}}</li>           
----------------------^
Expecting 'ID', 'DATA', got 'NUMBER' 

Anyway to access the json data for the templating, is the error at the template or the json? how can I fix it?

2 Answers 2

1

You need to wrap it with a square brackets:

<ul>
  {{#each this}}
    <li>{{[0]}}</li>
  {{/each}}
</ul>

Demo: http://jsbin.com/teduxeduvoqi/1/edit


A quote from the docs:

To reference a property that is not a valid identifier, you can use segment-literal notation, [

Sign up to request clarification or add additional context in comments.

Comments

0

Use it like this: {{this[0]}}.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.