kaljak
kaljak

Reputation: 1273

Nested keys in mustache template

I have following data structure:

var data = {
  labels: { name: "Name" },
  data: {
    name: "Layer 1",
    children: [
      {
        name: "Layer 1-1",
        children: [
          { name: "Layer 1-1-1" },
          { name: "Layer 1-1-2" }
        ]
      },
      {
        name: "Layer 1-2",
        children: [
          { name: "Layer 1-2-1" },
          { name: "Layer 1-2-2" }
        ]
      },
      { name: "Layer 1-3" }
    ]
  }
};

As you can see each layer can have it's own children. In this fiddle you can see, that the children are rendered multiple times: https://jsfiddle.net/kaljak/9xuLpnxp/

What do I have to change that the children are only rendered once?

Upvotes: 1

Views: 330

Answers (1)

Gilad Artzi
Gilad Artzi

Reputation: 3084

You have one to many {{#children}} tags, you should change the upper one to {{#data}}

See this fiddle: https://jsfiddle.net/9xuLpnxp/1/

Upvotes: 2

Related Questions