سؤال

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

هل كانت مفيدة؟

المحلول 2

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

نصائح أخرى

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top