PDA

View Full Version : Using a component template in a items array



georgetintin
3 Dec 2013, 8:19 AM
Hello, I'm having trouble getting a template to render whilst using it from within an items array, and also passing through variables. Code below:


Ext.define('MyTemplate', {
extend : 'Ext.Component',
alias : 'widget.mytemplate',

tpl : '<div><ul><li>{foo}</li><li>{bar}</li></ul></div>',

initComponent : function() {
this.callParent(arguments);
}
});

And being used in the items array from within my view component:


Ext.define('MyView', { extend : 'Ext.form.Panel',
alias : 'widget.myview',

initComponent: function() {
this.items = [
{ xtype : 'mytemplate', foo : 'foo', bar : 'bar' },
{ xtype : 'textfield', fieldLabel : 'My Textfield', name : 'mytextfield' }
];

this.callParent(arguments);
}
});

I'm sure I'm doing a thousand-and-one things wrong, could anyone give me any clues, please!?

burnnat
9 Dec 2013, 2:01 PM
Hopefully, you've figured this out by now, but you need to include your template values inside a data (http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.AbstractComponent-cfg-data) config. Here's a working fiddle:

21t