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

Traverse Up Nested Templates to Get Value #68

Open
difrnt opened this issue Feb 27, 2013 · 14 comments
Open

Traverse Up Nested Templates to Get Value #68

difrnt opened this issue Feb 27, 2013 · 14 comments

Comments

@difrnt
Copy link

difrnt commented Feb 27, 2013

Here's a working jsfiddle with the JSON and in the current form it works.
http://jsfiddle.net/FHZcA/

However is it possible to do something like: {{episodes.episode.name}}

<div id="list">
    <div data-template style="display: none;" data-from-map>Created On: {{value.createDate}}
        <div data-template-for="value.character">
             <h1>{{who.firstName}} {{who.lastName}}</h1>

            <div>
                 <h4>Episodes:</h4>

                <div data-template-for="episodes.episode">{{name}} {{date}}
                    <div data-template-for="details.places">{{episodes.episode.name}} - {{country}}</div>
                </div>
            </div>
            <div>
                 <h4>Ratings:</h4>

                <p data-template-for="ratings.category">{{type}}</p>
            </div>
        </div>
    </div>
    <p data-template-fallback>Sorry, JavaScript required!</p>
</div>
@mrolafsson
Copy link
Contributor

Yeah this should be straightforward using the _parent variable in a nested template. You can see this here: http://tempojs.com/2.0/examples/parentdata.html
For some reason it's not working here and I'm not exactly sure why - maybe it's the fact that the nested templates are two levels deep. I will have to investigate this - do you need the extra nesting around episodes > episode -> []?

@difrnt
Copy link
Author

difrnt commented Feb 27, 2013

@mrolafsson the JSON is a mockup to reflect one that I can't post for security reasons and that I also have no control over the formatting. 👎

Thanks, I'll take a look at the _parent var.

@mrolafsson
Copy link
Contributor

I understand completely - I'm trying to fix this now!

@mrolafsson
Copy link
Contributor

I think I'm on to something here - reporting back shortly.

@difrnt
Copy link
Author

difrnt commented Feb 27, 2013

@mrolafsson awesome! Thanks!

@mrolafsson
Copy link
Contributor

I've found the problem - looking for solution - thanks for your patience!

@mrolafsson
Copy link
Contributor

OK I hope I have fixed it - you can see your example here: http://jsfiddle.net/mr_olafsson/Jjwgb/
I altered HTML a little bit for my benefit - but principle is the same (I just prefer lists to divs with children).

Please can you check if this also works in IE? I can't test it here?

@difrnt
Copy link
Author

difrnt commented Feb 27, 2013

Works great (in Chrome/Firefox) in IE10 and IE9 I receive Sorry, JavaScript required!

@mrolafsson
Copy link
Contributor

Is that possibly just because IE doesn't like the mime type of the RAW from Github? I've tried testing the same file locally and when not using jsFiddle it works like a charm in IE 8 and 9.

@mrolafsson
Copy link
Contributor

Resolved one more corner case - how is it looking your side now?

@difrnt
Copy link
Author

difrnt commented Mar 4, 2013

Sorry about getting back to you a little later than I expected on this one. But on occasion I seem to receive a mixture of either blank data where it should be populated or the Sorry, JavaScript required! phrase.

@mrolafsson
Copy link
Contributor

Do you see any browser errors? It is a problem that Tempo fails to silently in some cases. I am working on a way around that.

@mrolafsson
Copy link
Contributor

You can now add your own error handler which might help with this:

Tempo.prepare('list').errors(function (err) {
    console.log('Whoa! something happened!');
    console.log(err);
}).render(data);

@mrolafsson
Copy link
Contributor

I take it this is fixed?

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