简体   繁体   中英

concatenate Ext.XTemplate

I have a component I'm creating which has a template. I want to call a function in that template that returns another template, and concatenate that template inside the other. I'm not sure how to do this, because I'm just learning how to work with templates.

So this is a simple code like the one I want to do.

    myFunction: function (){
        return = new Ext.XTemplate(
            '<span>{name}</span>',
            '<span>{lastname}</span>',
        );

    }
    ....... //more code

    var Tpl = new Ext.XTemplate(
            '<tpl>',
                '<span>{title}</span>',
            '<tpl for="person1">',
                  {this.myFunction()},
            '</tpl>',
            '<tpl for="person2">',
                  {this.myFunction()},
            '</tpl>',
            '</tpl>'
        );

.... //more code

Any help would be really appreciated.

Thanks!

Here is an example of a template which is applied multiple times by another template:

var subTemplate = new Ext.XTemplate(
    '<b>Hello {.}!</b>'
)
var mainTemplate = new Ext.XTemplate(
    '<tpl for".">',
        '{[this.applySubTemplate(values)]}<br/>',
    '</tpl>',
    {
        applySubTemplate: function(name) {
            return subTemplate.apply(name)
        }
    }
)

console.log(mainTemplate.apply(['World', 'Foo', 'Bar']))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM