PDA

View Full Version : Tamplate basics - need help



smick
12 Oct 2010, 10:15 AM
Hello,

I'm new to extjs and I'm trying to get my head around the use of templates.

The following code shows what I'm trying to do, it doesn't work of course. The issue is that the examples show templates being used through button clicks and not onloads. Also, if possible insteading of appending the template to an id, I'd like to store it in a variable to be dropped into a panel. Is this possible?


here's my conceptual code:


Ext.onReady(function() {

var html = '<a id="{id}" href="{url}" class="nav">{text}</a><br />';
var template = new Ext.Template(html);
template.compile();

template.update([ {
id: 'link1',
url: 'http://www.jackslocum.com/',
text: "Jack's Site"
}]);



var application = new Ext.Viewport({

layout: 'border',
items: [
{
region: "north",
contentEl: 'header'
},{
region: "center",
items: [{
xtype: 'panel',
html: [template]
}]

}
]
});
});



Thanks for any help.

Condor
13 Oct 2010, 3:12 AM
Ext.Template doesn't have an 'update' method.

You want:

var result = template.apply({
id: 'link1',
url: 'http://www.jackslocum.com/',
text: "Jack's Site"
});
...
xtype: 'panel',
html: result
ps. Why are you using [arrays] everywhere?

smick
13 Oct 2010, 8:47 AM
Thanks, that's a very clear answer. Re arrays everywhere, I actually have a lot of other elements I'm dropping in. The demo was just a trimmed down version. But likely I am using arrays where not necessary. ;) Thanks for the tip.