[英]Calculating in Ext Xtemplate
I try to do a calculation in a Ext XTemplate. 我尝试在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.
根据我阅读的文档,可以使用简单的{x + y}标签,但是这不适用于2个变量,所以我尝试使用{[x + y]},但随后模板渲染在此之后停止。
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. 我用我的尝试做了jsFiddle http://jsfiddle.net/VnFR3/1/ 。
Can anyone shed some light on this? 任何人都可以对此有所了解吗?
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.
文档不够清楚。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.