PDA

View Full Version : [4.1.0 beta 2] Error in XTemplate output if text contains { and }



ritcoder
30 Jan 2012, 11:09 AM
Hi all,
Ext.XTemplate is giving interesting output when used with text that contains {} Below are the code and responses


Ext.create('Ext.XTemplate','function {name}(){}').apply({name:'ben'})
output : TypeError: Cannot read property 'type' of undefined



Ext.create('Ext.XTemplate','function {name}()').apply({name:'ben'})

output: works


Ext.create('Ext.XTemplate','function {name}(){ return 20;}').apply({name:'ben'})
output: "function ben()"


Ext.create('Ext.XTemplate','function {name}(){{ return 20;}}').apply({name:'ben'})
"function ben(){}"


Ext.create('Ext.XTemplate','function {name}(){{ return 20;}}').apply({name:'ben'})
"function ben(){}"


Ext.create('Ext.XTemplate','function {name}(){{}}').apply({name:'ben'})
TypeError: Cannot read property 'type' of undefined


1. Is this a bug?
2. If not, how do you use XTemplate for expand text containing such data?
3. How do I get around this?

regards.

mitchellsimoens
30 Jan 2012, 11:44 AM
This sounds like why you can't use > in an if... because it means something. You have to use >

ritcoder
30 Jan 2012, 11:56 AM
Not following. There is no > in my code.
Did you mean } ?

mitchellsimoens
30 Jan 2012, 12:02 PM
Was an example that is in the documentation.

ritcoder
30 Jan 2012, 12:20 PM
I just searched the documentation for XTemplate. I could find not such thing. Can you please point me to the section so I can just search for it.

I have seen the one on >. That is not what I'm using. The issue I'm having has to do with { and }. In .NET, we used {{ and }} for the literal. Tried that, as you can see from the initial code, but it did not work.

ritcoder
3 Feb 2012, 2:19 PM
Haven't heard anything else about this.
Is this an error? Am I doing something wrong?
I ended up using _.tempate which uses <%= %>. It works but I do prefer the {} syntax used by extjs.

westy
30 Mar 2012, 7:01 AM
Just stumbled upon this... I think what Mitchell is saying is that the curly braces need to be escaped.

You tried using \u007B and \u007D for { and } respectively?

ritcoder
30 Mar 2012, 9:23 AM
Well, I tried


Ext.create('Ext.XTemplate','function {name}()\u007B \u007D').apply({name:'ben'})

Got the error:

TypeError: Cannot read property '1' of null

I used google chrome. 4.1.0rc1

jamesmoey
6 Jun 2012, 10:42 PM
Try "{['{']}" and "{['}']}"