4

I've a json object like this

[Object]
0: Object
    domains: Array[1]
    0: "domain1.com"
    length: 1
    __proto__: Array[0]
    name: "name1"
1: Object
    domains: Array[2]
    0: "domain2.com"
    length: 1
    __proto__: Array[0]
    name: "name2"

These objects are generated on the client and I want to display them by using jQuery.tmpl plugin. I've defined a template to be:

<script id="domain_template" type="text/x-jquery-tmpl">
  {{each response}}
    {{each response.domains}}
      <div class="dummy_copy" data-srvType="${srvType}" data-domain="${domain}">"${value}"</div>
    {{/each}}
  {{/each}}
</script>

What did i do wrong with it here? thanks

1
  • Please provide your JS and JSON object in string form. Commented Oct 7, 2013 at 11:14

2 Answers 2

1

You're code should be:

{{each response}}
    {{each $value.domains}}

or

{{each response}}
    {{each domains}}

and if you wont to have values: srvType, domain, value they must be members of objects that you store in domains

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

Comments

1

First of all, i convert to JSON my object like this.

arr = []
  for srv in response
    for domain in srv.domains
      arr.push srvType: srv.srvType, domain: domain
domainTmpl = $.tmpl $(@domainTemplate).template(), arr

After having json object it was rendered by jquery template.This will helpfull for all i think

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.