Reputation: 765
I try to do a calculation in a Ext XTemplate. According to the docs i read that is possible with a simple {x + y} tag, but that din't work with 2 variables, so i tried doing it with {[x + y]} but then the template rendering stops after that.
var tpl = new Ext.XTemplate('{x} + {y} = {[x + y]} thats it.');
console.log( tpl.apply({x: 1.5, y: 2}) );
results in.
1.5 + 2 =
I've made jsFiddle http://jsfiddle.net/VnFR3/1/ with how I tried.
Can anyone shed some light on this?
Upvotes: 1
Views: 620
Reputation: 15673
Try this:
var tpl = new Ext.XTemplate('{x} + {y} = {[values.x+values.y]} thats it');
console.log( tpl.apply({x: 1.5, y: 2}) );
Alternative with functions:
var tpl = new Ext.XTemplate('{x} + {y} = {[values.x+values.y]} or ',
'{[this.add( values.x,values.y )]}',{
add:function(x,y){
return x+y;
}
});
console.log( tpl.apply({x: 1.5, y: 2}) );
The important distinction from your code is the use of values object inside the [] code execution template. The docs do not make that clear enough.
Upvotes: 3