V
V
vohaha2015-10-29 22:50:06
JavaScript
vohaha, 2015-10-29 22:50:06

What is the best way to display data from an ajax request?

I parse the received data in this way

getData = (data)->
    productContainer = []
    productProperty = []
    for product, i in data
      productContainer.push('<div id="product_' + i + '"></div>')
      for property, value of product
        productProperty.push('<div class="product__' + property + '">' + property + ' - ' + value + '</div>')

How to output data like this:
<div id="product_0">
    <div class="product__prop1">prop1 - stuff</div>
    <div class="product__prop2">prop2 - stuff</div>
    <div class="product__prop3">prop3 - stuff</div>
    <div class="product__prop4">prop4 - stuff</div>
</div>

what not to work with the house every iteration?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Ineshin, 2015-10-29
@vohaha

Just use a template engine:
- Handlebars.js
- Dust.js

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question