kanor1306
kanor1306

Reputation: 168

Sencha Touch: Is it possible to add a script to a template?

Is there any way to make something like the following?

var template=new Ext.XTemplate(
'<tpl for=".">',
'<div>'
            '<span>This is a Test number {id}</span>'
    '<script>doSomething()</script>',
'</div>',
'</tpl>');

By doing that, i just receive the HTML with the script tags, but they are not executed. Any idea?

Upvotes: 0

Views: 614

Answers (1)

Pavel Podlipensky
Pavel Podlipensky

Reputation: 8269

If you want to run javascript code while generating html by template, you can do the following:

var template=new Ext.XTemplate(
'<tpl for=".">',
'<div>'
    '<span>This is a Test number {id}</span>'
    '{[this.doSomething()]}',
'</div>',
'</tpl>',
{
   doSomething: function(){}
});

Upvotes: 1

Related Questions