Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested object in array #93

Closed
AllyReid opened this issue Feb 9, 2015 · 6 comments
Closed

Nested object in array #93

AllyReid opened this issue Feb 9, 2015 · 6 comments

Comments

@AllyReid
Copy link

AllyReid commented Feb 9, 2015

How can I access the values of an object within my data array JSON?

e.g.

sports:{
"0":"football",
"1":"golf",
"2":"basketball"
}

I have been using your nested examples but not having any luck getting it to work

@mrolafsson
Copy link
Contributor

Can you give me an example of what you are trying to output this as? This is not an array so you would want to use data-from-map attribute: https://github.com/twigkit/tempo/blob/master/examples/data-from-map.html

@AllyReid
Copy link
Author

Hi,

It's to display some profile information, e.g.

JSON:

postcode: "ABC 123"
region: "UK"
section: "Members"
sports:{
"0":"football",
"1":"golf",
"2":"basketball"
}

HTML:

<div class="inner" data-template>
  <div class="thumbnail-name">
    <img src="http://dummyimage.com/300/300/fff" alt="" data-src="{{image}}" />
    <h3>{{section}} {{region}}</h3>
  </div>
    <ul>
    <span>Sports</span>  
    <li>{{sports}}</li>
    </ul>
</div>

@mrolafsson
Copy link
Contributor

If you supply a Fiddle I could help you with this but this is a straight forward case of what I said. You need to handle the iteration of sports not just refer to a single object. And since Sports is not an array you need to traverse it as a map.

@mrolafsson
Copy link
Contributor

There were a few issues with your example including invalid JSON, lack of iteration etc. Here you'll find a working example: http://jsfiddle.net/mr_olafsson/67yreg0h/

Check out nested templates: http://tempojs.com/#nested-templates

<ol id="list">
    <li data-template data-from-map>{{value}} - {{key | append '@marx.com'}}</li>
</ol>

@AllyReid
Copy link
Author

Wow fixed the json and it works perfectly!

Thanks for your quick replies and examples.

Thanks for such a great tool.

@mrolafsson
Copy link
Contributor

You're welcome! ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants