PDA

View Full Version : Template with period in dataIndex.



incutonez
25 Jul 2014, 9:50 AM
I'm trying to create an XTemplate, and one of my dataIndexes has a period... so my data looks something like this:

{
"one": 1,
"two.one": 21,
"two.two": 22
}

Now, when I'm creating the template, I can't do something like {two.one} because that thinks "two" is the beginning of an object, and then I'm accessing its key "one." I've tried doing something like {'two.one'}, but this also doesn't work, and I've tracked it down to the culprit in the code... in Ext.XTemplateCompiler.parseTag (http://docs.sencha.com/extjs/4.2.1/source/XTemplateCompiler.html#Ext-XTemplateCompiler-method-parseTag), this code is what breaks it:



// compound Javascript property name (e.g., "foo.bar")
else if (isNaN(name) && name.indexOf('-') == -1 && name.indexOf('.') != -1) {
v = "values." + name;
}
// number or a '-' in it or a single word (maybe a keyword): use array notation
// (http://jsperf.com/string-property-access/4)
else {
v = "values['" + name + "']";
}


So with my two.one string, I get into that else if, but what I really want is the else that follows right after it. Unfortunately, it doesn't seem like I can override this in an easy way... does anybody have any thoughts? I'm using Ext JS 4.2.1.

skirtle
25 Jul 2014, 10:21 AM
Escaping in XTemplates is a mess. This works:


new Ext.XTemplate('{[values["one.two"]]}').apply({'one.two': 12});

incutonez
25 Jul 2014, 10:32 AM
Genius! Using {[values['two.one']]} instead of {two.one} was the ticket. Thank you so much!