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

Recursive traversal #185

Closed
jiuker opened this issue Jan 20, 2016 · 3 comments
Closed

Recursive traversal #185

jiuker opened this issue Jan 20, 2016 · 3 comments

Comments

@jiuker
Copy link

jiuker commented Jan 20, 2016

if we have a data that is like this:

var showData = {
                    data: [{
                        data: [{
                            data: [],
                            show: [{
                                a: 7
                            }, {
                                a: 8
                            }, {
                                a: 9
                            }]
                        }],
                        show: [{
                            a: 4
                        }, {
                            a: 5
                        }, {
                            a: 6
                        }]
                    }],
                    show: [{
                        a: 1
                    }, {
                        a: 2
                    }, {
                        a: 3
                    }]
                }

but it has unkown floors,
now I do like this:

{{##def.s: 
                        {{~it.show:v:i}}
                       xx{{=v.a}}
                        {{~}} 
                        {{? it.data.length!=0}}
                     {{~it.data}} 
                     {{ out +=partText(v);}} //this is very importemt
                     {{~}} 
                     {{?}}
                        #}} 
                      {{#def.s}}
var partText = doT.template(parttmpl.text);

I think you should add this surport,dont like me

@houd1ni
Copy link

houd1ni commented Apr 20, 2016

feel free to reopen #191 due to maintain issues with this fork

@epoberezkin
Copy link
Collaborator

@jiuker to implement recursive templates with doT you need to pass compiled template function as a property of a context object.

So instead of {{ out +=partText(v);}} you would {{= it.partText(v);}} ({{= and {{ out+= is the same, the former is how it usually used) and when you call template you need to assign template function to a property of data you pass to template.

I hope it makes sense

@epoberezkin
Copy link
Collaborator

Also see #34

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

No branches or pull requests

3 participants