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

Can you show me a demo with parent path (../) ? #925

Closed
javagtcpp opened this issue Dec 16, 2014 · 6 comments
Closed

Can you show me a demo with parent path (../) ? #925

javagtcpp opened this issue Dec 16, 2014 · 6 comments
Labels
Milestone

Comments

@javagtcpp
Copy link

I see document carefully on handlebars website(http://handlebarsjs.com/). Scroll to Handlebars Paths, The "../" means i can get a relative parent template scope, but the simplest demo can work well, not a little complicated. I tried write a data context like this:

var context = {
                story: [3, 4, 5, 10],
                total: 10,
                aga: [{
                    story: [3, 4, 5, 11],
                    total: 11
                }, {
                    story: [3, 4, 5, 13],
                    total: 13
                }]
            };

And i want iterate output : story[i] / total for percentage. The template code like this:

        ul>
                       <-- add this for descrption ->
                       <-- part 1 ->
            {{#each story}}  
            li>{{calc this ../total}}/li>
            {/each}
                       <-- part 2 ->
            {#each aga}
            {#each story}
            li>{{calc this ../total}}/li>
        {/each}
            {/each}
        /ul>

When i put [part 1] before [part 2], then i get error: Uncaught TypeError: Cannot read property '1' of undefined ! Because the last args(depths) is undefined. And I try set [part 1] after [part 2], then it worked. I was so confused for parent path, and never see a perfect demo can explain this(../).
blocker "calc" is simple output, like:

var template = Handlebars.compile($('#entry-template').html());
            $(template(context, {
                helpers: {
                    'calc': function(num, total){
                        return num + ' / ' + total;
                    }
                }
            })).appendTo('body');
``
I haven't solve this problem yet. Can somebody help me, or show the usage of parent path(../) ?
@javagtcpp
Copy link
Author

I alter some tag name in what i write to keep code, not formated!

@kpdecker
Copy link
Collaborator

I'm not really sure exactly what your template is as it seems like it's missing things. Could you show an example of this failure using this template?
http://jsfiddle.net/9D88g/26/

@kpdecker kpdecker added this to the 3.0 milestone Dec 16, 2014
@javagtcpp
Copy link
Author

Oh, sorry, this is the link: http://jsfiddle.net/24z4q3ra/2/, I want output list, but this will lead to an error. We can not see the error in jsfiddle.net page, but we can write a demo and see error in console window. the next link will out put right result : http://jsfiddle.net/2b7uye2p/, I just adjust the handlebars template orderinal. Why ?

@kpdecker
Copy link
Collaborator

Ironically this is the exact same issue that my own team found yesterday. Fixed in #926. If you add a space or similar in one of the children (http://jsfiddle.net/24z4q3ra/3/) it should work until the fix for #926 is released.

@kpdecker
Copy link
Collaborator

Thanks for providing the fiddle!

@kpdecker
Copy link
Collaborator

It's a bug that is fixed in master but the workaround is in the link I posted in my last comment.

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

No branches or pull requests

2 participants