Question

After a 4.1.1 upgrade I noticed a quirky change in a way how XTemplate interprets null value. Here is an example of what XTemplate does http://jsfiddle.net/dbrin/AyJ9v/3/ (note Field 2 value) . And here is the same but interpreted by Template class: http://jsfiddle.net/dbrin/AyJ9v .

When data passed to an XTemplate contains null values string "null" is printed to the output.

If this is a bug in 4.1.1 what is the workaround if I need the use of XTemplate?

Thanks.

update: Bug was fixed in 4.1.2

Was it helpful?

Solution

This workaround will work (here's the JsFiddle):

var tpl = new Ext.XTemplate("<p>Field1: {f1}, Field2: {[this.outputField( values.f2 )]} </p>",{
    outputField: function( aValue )
    {
        return aValue == null ? '' : aValue;                
    }
}).compile();

OTHER TIPS

If you want to have condition inline.

var tpl = new Ext.XTemplate("<tpl if='f2 != null'>{f2}</tpl>" ,
<tpl if='f2 == null'></tpl>").compile();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top