PDA

View Full Version : Model not being created from JSON object



castitas
18 May 2012, 8:31 AM
I have three different models that share some similar fields, namely the calendar months, which makes them interchangeable. I have a function that totals two grids into a JSON object:


function totals(myRsc, mainStore, totalStore, otherStore){
var mainTotal = {id:0},
otherTotal = {id:1},
total = {id:2};

Ext.each(myRsc.down('#gridone').columns,function(col, colNum){
if(colNum>1) { //This check skips the action & name columns
mainTotal[col.dataIndex] = mainStore.sum(col.dataIndex);
otherTotal[col.dataIndex] = otherStore.sum(col.dataIndex);
total[col.dataIndex] = mainTotal[col.dataIndex] + otherTotal[col.dataIndex];
}
});

myRsc.totalFutTime = new app.model.TotalGridModel(total);
totalStore.loadRawData([mainTotal],false);
}

If I use TotalGridModel, myRsc.totalFutTime has no data (unless I put the id property in, as above, then only 'id' shows up). If I use the other two, then it works just fine. I've tried specifying an idProperty (even though the TotalGridModel doesn't need one), but it doesn't seem to make a difference. Any ideas?

castitas
18 May 2012, 8:41 AM
Ext.define('app.model.TotalGridModel', {
extend: 'Ext.data.Model',
idProperty: 'name',
fields: ['name',
//months
{name: 'jan', type: 'float', convert: convert}, {name: 'feb', type: 'float', convert: convert},
{name: 'mar', type: 'float', convert: convert}, {name: 'apr', type: 'float', convert: convert},
{name: 'may', type: 'float', convert: convert}, {name: 'june',type: 'float', convert: convert},
{name: 'july',type: 'float', convert: convert}, {name: 'aug', type: 'float', convert: convert},
{name: 'sept',type: 'float', convert: convert}, {name: 'oct', type: 'float', convert: convert},
{name: 'nov', type: 'float', convert: convert}, {name: 'dec', type: 'float', convert: convert},
//actuals
{name: 'actual0', type: 'float', convert: convert}, {name: 'actual1', type: 'float', convert: convert},
{name: 'actual2', type: 'float', convert: convert}, {name: 'actual3', type: 'float', convert: convert},
{name: 'actual4', type: 'float', convert: convert}, {name: 'actual5', type: 'float', convert: convert},
{name: 'actual6', type: 'float', convert: convert}
]
});



Ext.define('app.model.EmployeeEffortModel', {
extend: 'Ext.data.Model',
idProperty: 'project_id',
fields: ['project_id', 'project_name', 'hr_work_id', 'fund_color',
//months
{name: 'jan', type: 'int', useNull: true}, {name: 'feb', type: 'int', useNull: true},
{name: 'mar', type: 'int', useNull: true}, {name: 'apr', type: 'int', useNull: true},
{name: 'may', type: 'int', useNull: true}, {name: 'june',type: 'int', useNull: true},
{name: 'july',type: 'int', useNull: true}, {name: 'aug', type: 'int', useNull: true},
{name: 'sept',type: 'int', useNull: true}, {name: 'oct', type: 'int', useNull: true},
{name: 'nov', type: 'int', useNull: true}, {name: 'dec', type: 'int', useNull: true},
//id's
{name: 'janid', type: 'int'}, {name: 'febid', type: 'int'}, {name: 'marid', type: 'int'},
{name: 'aprid', type: 'int'}, {name: 'mayid', type: 'int'}, {name: 'juneid',type: 'int'},
{name: 'julyid',type: 'int'}, {name: 'augid', type: 'int'}, {name: 'septid',type: 'int'},
{name: 'octid', type: 'int'}, {name: 'novid', type: 'int'}, {name: 'decid', type: 'int'},
//funding
{name: 'janfnd', type: 'boolean'}, {name: 'febfnd'}, {name: 'marfnd' },
{name: 'aprfnd' }, {name: 'mayfnd'}, {name: 'junefnd'},
{name: 'julyfnd'}, {name: 'augfnd'}, {name: 'septfnd'},
{name: 'octfnd' }, {name: 'novfnd'}, {name: 'decfnd' },
//actuals
{name: 'actual0', type: 'int'}, {name: 'actual1', type: 'int'},
],
...
}



Ext.define('app.model.EmployeeOtModel', {
extend: 'Ext.data.Model',
idProperty: 'project_id',
fields: ['project_id', 'project_name', 'hr_work_id', 'fund_color',
//months
{name: 'jan', type: 'int', useNull: true}, {name: 'feb', type: 'int', useNull: true},
{name: 'mar', type: 'int', useNull: true}, {name: 'apr', type: 'int', useNull: true},
{name: 'may', type: 'int', useNull: true}, {name: 'june',type: 'int', useNull: true},
{name: 'july',type: 'int', useNull: true}, {name: 'aug', type: 'int', useNull: true},
{name: 'sept',type: 'int', useNull: true}, {name: 'oct', type: 'int', useNull: true},
{name: 'nov', type: 'int', useNull: true}, {name: 'dec', type: 'int', useNull: true},
//actuals
{name: 'actual0', type: 'int'}, {name: 'actual1', type: 'int'},
{name: 'actual2', type: 'int'}, {name: 'actual3', type: 'int'},
{name: 'actual4', type: 'int'}, {name: 'actual5', type: 'int'},
{name: 'actual6', type: 'int'}
]
});

castitas
18 May 2012, 8:45 AM
It was my convert function. I forgot to return anything, it "converted" everything to null.