Im making a Sencha Touch PhoneGap-app. I'm trying to add a field with a conversion function to a model in Sencha Touch 2.1 This conversion function is supposed to find individual letters and replace them ("convFAF").
I can't understand why it fails.
With the function in place, the list that (lists the store that) uses the model shows up blank. Xcode doesn't print any error message to the console.
My model:
Ext.define('Labblistan.model.LabItem', {
extend: 'Ext.data.Model',
config: {
fields: [
{name: 'Group', type: 'String'},
{name: 'Groupname', type: 'String'},
{name: 'Analysis', type: 'String'},
{name: 'Sex', type: 'String'},
{name: 'AgeFrom', type: 'String'},
{name: 'AgeTo', type: 'String'},
{name: 'LowLimit', type: 'String'},
{name: 'UpperLimit', type: 'String'},
{name: 'Unit', type: 'String'},
{name: 'Comment', type: 'String'},
{name: 'SortOrder', type: 'String'},
{
name : 'formattedAnalysis',
type : 'string',
convert : function(v, record) {
var unformattedAnalysis = record.get('Analysis');
if (unformattedAnalysis.indexOf("-") != -1) {
return unformattedAnalysis.substring(unformattedAnalysis.indexOf("-")).substr(1).toUpperCase();
} else {
return unformattedAnalysis.toUpperCase();
}
}},
{name: 'formattedAgeFrom', convert: convertAgeFrom},
]
},
});
function convertAgeFrom(v, record) {
var unformattedAgeFrom = record.get('AgeFrom');
var formattedAgeFrom = unformattedAgeFrom.replace('d', ' d.').replace('y', ' år').replace('m', ' mån.').replace('w', ' v.');
return formattedAgeFrom;
}
As you can see I already have a conversion function going ("formattedAnalysis" - which works fine).
I've tried having the function inside the field definition (as per formattedAnalysis) but with the same results. I've also tried setting AgeFrom type to Auto (as well auto and string for formattedAgeFrom
The strangest part is that if I switch record.get('AgeFrom'); to 'Analysis', the function works. It also seems to works with Group, Unit, and SortOrder but not with AgeFrom or AgeTo (the two fields I'm now interested in converting).
The data is loaded from an XML file, a copy of which can be found here
I thought adding this conversion would be easy but I'm at a total loss here. Any help or ideas are deeply appreciated.
stringas type in model. BTW whats the error you are getting? - ThinkFloyd