0

I get a JSON array list of objects from database.

this is spitted to client side on page load of the current usercontrol

    var json = new JavaScriptSerializer();
    var jsonList = json.Serialize(mylList);             
    Page.ClientScript.RegisterStartupScript(this.GetType(), "HomeCarouselScript", string.Concat("<script type='text/javascript'> var carouselData = ", jsonList, ";</script>"));

the json structure is like this json has collection of objects called Active. each active object has property called Name, Lastname, Address

i want to display all the objects in to HTML div in this structure for each object present can we add following template to the main container. for each existing object in the j son list i am trying to add it the main div container.

<div id="maincontainer">
   <div class="item">
         Object.Name
         <div class="subcategory">
            <h4>
              Object.Age
            </h4>
            <p>               
             Object.Address
            </p>
          </div>
     </div>

1 Answer 1

1

You can use an HTML template engine like Mustache or Handlebars and turn your markup into something like this:

{{#each item}}  
      <div class="item">
        {{Name}}
          <div class="subcategory">
            <h4>
              {{Age}}
            </h4>
            <p>               
              {{Address}}
            </p>
          </div>
      </div>
{{/each}}
Sign up to request clarification or add additional context in comments.

3 Comments

is it supported in IE8 and other browsers... we tried angular which is not supported in IE8 and now we have to re do again
According to docs, handlebars supports IE6+. Btw, angular 1.2 still supports IE8.
angular really just 1.2 or 1.2.26 as well

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.