Patrick Klug
Patrick Klug

Reputation: 14391

how to create data templates in html

I am a JS, html beginner and trying to understand how to define/create a html representation of a data object.

Say I have a list of people (in JSON for example) where each person has the following properties: firstName, lastName, age, photo, description.

How would you normally display this list in html?

I assume that somewhere is a div place holder for the list which then gets populated in JS but I'm not sure how the template for the person itself is defined.

Is there a recommended way of doing this sort of thing?

If someone can show me an example that would be great.

Upvotes: 2

Views: 4165

Answers (3)

Kernel James
Kernel James

Reputation: 4064

There is also http://code.google.com/p/distal for starters. It has a syntax familiar to HTML coders.

<div data-qtext="obj.firstName"></div>

Upvotes: 0

Matthias
Matthias

Reputation: 12259

There are plenty of frameworks for templates, e.g.:

Upvotes: 1

Adaz
Adaz

Reputation: 1665

Have a look at http://handlebarsjs.com/ for a start. This will take your json and format it the way you want.

You can also use jquery Ajax method and then just loop through your results and generate HTML.

Upvotes: 1

Related Questions