/** * @class Ext.Template *
Represents an HTML fragment template. Templates may be {@link #compile precompiled} * for greater performance.
*For example usage {@link #Template see the constructor}.
* * @constructor * An instance of this class may be created by passing to the constructor either * a single argument, or multiple arguments: *
var t = new Ext.Template("<div>Hello {0}.</div>");
t.{@link #append}('some-element', ['foo']);
* join('')
.
var t = new Ext.Template([
'<div name="{id}">',
'<span class="{cls}">{name:trim} {value:ellipsis(10)}</span>',
'</div>',
]);
t.{@link #compile}();
t.{@link #append}('some-element', {id: 'myid', cls: 'myclass', name: 'foo', value: 'bar'});
* join('')
.
*
var t = new Ext.Template(
'<div name="{id}">',
'<span class="{cls}">{name} {value}</span>',
'</div>',
// a configuration object:
{
compiled: true, // {@link #compile} immediately
}
);
* Notes:
*disableFormats
are not applicable for Sencha Touch.values
to the template and appends
* the new node(s) to the specified el
.
* For example usage {@link #Template see the constructor}.
* @param {Mixed} el The context element * @param {Object/Array} values * The template values. Can be an array if the params are numeric (i.e.{0}
)
* or an object (i.e. {foo: 'bar'}
).
* @param {Boolean} returnElement (optional) true to return an Ext.Element (defaults to undefined)
* @return {HTMLElement/Ext.Element} The new node or Element
*/
append: function(el, values, returnElement) {
return this.doInsert('beforeEnd', el, values, returnElement);
},
doInsert: function(where, el, values, returnEl) {
el = Ext.getDom(el);
var newNode = Ext.DomHelper.insertHtml(where, el, this.applyTemplate(values));
return returnEl ? Ext.get(newNode, true) : newNode;
},
/**
* Applies the supplied values to the template and overwrites the content of el with the new node(s).
* @param {Mixed} el The context element
* @param {Object/Array} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})
* @param {Boolean} returnElement (optional) true to return a Ext.Element (defaults to undefined)
* @return {HTMLElement/Ext.Element} The new node or Element
*/
overwrite: function(el, values, returnElement) {
el = Ext.getDom(el);
el.innerHTML = this.applyTemplate(values);
return returnElement ? Ext.get(el.firstChild, true) : el.firstChild;
},
// private function used to call members
call: function(fnName, value, allValues) {
return this[fnName](value, allValues);
}
};
/**
* Alias for {@link #applyTemplate}
* Returns an HTML fragment of this template with the specified values
applied.
* @param {Object/Array} values
* The template values. Can be an array if the params are numeric (i.e. {0}
)
* or an object (i.e. {foo: 'bar'}
).
* @return {String} The HTML fragment
* @member Ext.Template
* @method apply
*/
Ext.Template.prototype.apply = Ext.Template.prototype.applyTemplate;