PDA

View Full Version : problem with model designing



sveatlo
6 Feb 2013, 8:39 AM
Hi,
I've got a little problem with designing my models.

I get this response from server:


[
{
"success": "true",
"data": {
"sromain": [
{
"corporation": "DEV 1 s.r.o.",
"dbName": "dev_1_s_r_o_",
"prijmyCelk": "2 106,00 €",
"nakladyCelk": "2 049,00 €",
"ziskCelk": "57,00 €",
"neuhrVydCelk": "2 106,00 €",
"neuhrPrijCelk": "2 049,00 €",
"dph": "9,52 €"
}
],
"branches": [
{
"branch_name": "Bratislava",
"branch_code": "BA",
"strediskoprijmyCelk": "180,00 €",
"strediskonakladyCelk": "0,00 €",
"strediskoziskCelk": "180,00 €",
"strediskoneuhrVydCelk": "180,00 €",
"strediskoneuhrPrijCelk": "0,00 €",
"streddphCelk": "30,00 €"
},
{
"branch_name": "Banskα Bystrica",
"branch_code": "BB",
"strediskoprijmyCelk": "600,00 €",
"strediskonakladyCelk": "0,00 €",
"strediskoziskCelk": "600,00 €",
"strediskoneuhrVydCelk": "600,00 €",
"strediskoneuhrPrijCelk": "0,00 €",
"streddphCelk": "100,00 €"
},
{
"branch_name": "Centrαla",
"branch_code": "C",
"strediskoprijmyCelk": "666,00 €",
"strediskonakladyCelk": "213,00 €",
"strediskoziskCelk": "453,00 €",
"strediskoneuhrVydCelk": "666,00 €",
"strediskoneuhrPrijCelk": "213,00 €",
"streddphCelk": "75,52 €"
},
{
"branch_name": "Košice",
"branch_code": "KE",
"strediskoprijmyCelk": "420,00 €",
"strediskonakladyCelk": "1 836,00 €",
"strediskoziskCelk": "-1 416,00 €",
"strediskoneuhrVydCelk": "420,00 €",
"strediskoneuhrPrijCelk": "1 836,00 €",
"streddphCelk": "-236,00 €"
},
{
"branch_name": "Nitra",
"branch_code": "NR",
"strediskoprijmyCelk": "240,00 €",
"strediskonakladyCelk": "0,00 €",
"strediskoziskCelk": "240,00 €",
"strediskoneuhrVydCelk": "240,00 €",
"strediskoneuhrPrijCelk": "0,00 €",
"streddphCelk": "40,00 €"
}
]
}
}
]


My store:


Ext.define('Statistics.store.SroMain', {
extend: 'Ext.data.Store',

model: 'Statistics.model.SroMain',
storeId: 'SroMain',
fields: [
],
proxy: {
type: 'ajax',
url: 'resources/scripts/get_sromain.php',
reader: {
type: 'json',
root: 'data'
},
},

});

And models:


Ext.define('Statistics.model.SroMain', {
extend: 'Ext.data.Model',
hasOne: {model: 'Statistics.model.HomeTables', name: 'sromain'},
hasMany: {model: 'Statistics.model.Branches', name: 'branches'}

});



Ext.define('Statistics.model.HomeTables', {
extend: 'Ext.data.Model',
fields: [
{name: 'corporation'},
{name: 'dbName'},
{name: 'prijmyCelk'},
{name: 'nakladyCelk'},
{name: 'ziskCelk'},
{name: 'neuhrVydCelk'},
{name: 'neuhrPrijCelk'},
{name: 'dph'}
]
});



Ext.define('Statistics.model.Branches', {
extend: 'Ext.data.Model',
fields: [
{name: 'branch_name'},
{name: 'branch_code'},
{name: 'strediskoprijmyCelk'},
{name: 'strediskonakladyCelk'},
{name: 'strediskoziskCelk'},
{name: 'strediskoneuhrVydCelk'},
{name: 'strediskoneuhrPrijCelk'},
{name: 'streddphCelk'}
]
});


And I data to appear in a dataview:


...
{
xtype: 'dataview',
store: Ext.data.StoreManager.lookup('SroMain'),
tpl: new Ext.XTemplate(
'<tpl for="sromain">',
'<table id="tfhover" class="tftable" style="margin-bottom: 10px;">',
'<caption class="x-panel-header-default"><a href="#{dbName}">{corporation}</a></caption>',
'<tr><td colspan="2">'+translation[lang].home.table.expenses+':<br>{nakladyCelk}</td><td colspan="2">'+translation[lang].home.table.profit+':<br>{ziskCelk}</td><td colspan="2">'+translation[lang].home.table.revenues+':<br>{prijmyCelk}</td></tr>',
'<tr><td colspan="2">'+translation[lang].home.table.expensesnot+':<br>{neuhrPrijCelk}</td><td colspan="2">'+translation[lang].home.table.vat+': <br>{dph}</td><td colspan="2">'+translation[lang].home.table.revenuesnot+':<br>{neuhrVydCelk}</td></tr>',
'</table>',
'</tpl>',
'<tpl for="branches">',
'<table id="tfhover" class="tftable" style="margin-bottom: 10px;">',
'<caption class="x-panel-header-default"><a href="#{dbName}">{corporation}</a></caption>',
'<tr><td colspan="2">'+translation[lang].home.table.expenses+':<br>{nakladyCelk}</td><td colspan="2">'+translation[lang].home.table.profit+':<br>{ziskCelk}</td><td colspan="2">'+translation[lang].home.table.revenues+':<br>{prijmyCelk}</td></tr>',
'<tr><td colspan="2">'+translation[lang].home.table.expensesnot+':<br>{neuhrPrijCelk}</td><td colspan="2">'+translation[lang].home.table.vat+': <br>{dph}</td><td colspan="2">'+translation[lang].home.table.revenuesnot+':<br>{neuhrVydCelk}</td></tr>',
'</table>',
'</tpl>'
),
multiSelect: true,
trackOver: true,
deferEmptyText: false,
emptyText: 'No data',

}
...

Can you please help me how to change my models?

Thanks for any replie

mitchellsimoens
8 Feb 2013, 11:33 AM
Quite a few things here. Your data is not correct, it needs to be (notice the lack of the two arrays):


{
"success" : "true",
"data" : {
"sromain" : {
"corporation" : "DEV 1 s.r.o.",
"dbName" : "dev_1_s_r_o_",
"prijmyCelk" : "2 106,00 €",
"nakladyCelk" : "2 049,00 €",
"ziskCelk" : "57,00 €",
"neuhrVydCelk" : "2 106,00 €",
"neuhrPrijCelk" : "2 049,00 €",
"dph" : "9,52 €"
},
"branches" : [
{
"branch_name" : "Bratislava",
"branch_code" : "BA",
"strediskoprijmyCelk" : "180,00 €",
"strediskonakladyCelk" : "0,00 €",
"strediskoziskCelk" : "180,00 €",
"strediskoneuhrVydCelk" : "180,00 €",
"strediskoneuhrPrijCelk" : "0,00 €",
"streddphCelk" : "30,00 €"
},
{
"branch_name" : "Banskα Bystrica",
"branch_code" : "BB",
"strediskoprijmyCelk" : "600,00 €",
"strediskonakladyCelk" : "0,00 €",
"strediskoziskCelk" : "600,00 €",
"strediskoneuhrVydCelk" : "600,00 €",
"strediskoneuhrPrijCelk" : "0,00 €",
"streddphCelk" : "100,00 €"
},
{
"branch_name" : "Centrαla",
"branch_code" : "C",
"strediskoprijmyCelk" : "666,00 €",
"strediskonakladyCelk" : "213,00 €",
"strediskoziskCelk" : "453,00 €",
"strediskoneuhrVydCelk" : "666,00 €",
"strediskoneuhrPrijCelk" : "213,00 €",
"streddphCelk" : "75,52 €"
},
{
"branch_name" : "Košice",
"branch_code" : "KE",
"strediskoprijmyCelk" : "420,00 €",
"strediskonakladyCelk" : "1 836,00 €",
"strediskoziskCelk" : "-1 416,00 €",
"strediskoneuhrVydCelk" : "420,00 €",
"strediskoneuhrPrijCelk" : "1 836,00 €",
"streddphCelk" : "-236,00 €"
},
{
"branch_name" : "Nitra",
"branch_code" : "NR",
"strediskoprijmyCelk" : "240,00 €",
"strediskonakladyCelk" : "0,00 €",
"strediskoziskCelk" : "240,00 €",
"strediskoneuhrVydCelk" : "240,00 €",
"strediskoneuhrPrijCelk" : "0,00 €",
"streddphCelk" : "40,00 €"
}
]
}
}

And then had to tweak the Statistics.model.SroMain model:


Ext.define('Statistics.model.SroMain', {
extend : 'Ext.data.Model',
hasOne : { model : 'Statistics.model.HomeTables', name : 'sromain', associationKey : 'sromain' },
hasMany : { model : 'Statistics.model.Branches', name : 'branches' }
});

And then had to tweak your dataview:


new Ext.panel.Panel({
renderTo : document.body,
width : 400,
height : 400,
title : 'Test',
layout : 'fit',
items : [
{
xtype : 'dataview',
store : new Statistics.store.SroMain({
autoLoad : true
}),
tpl : new Ext.XTemplate(
'<tpl for=".">',
'<div class="row">',
'<table id="tfhover" class="tftable" style="margin-bottom: 10px;">',
'<caption class="x-panel-header-default"><a href="#{sromain.dbName}">{sromain.corporation}</a></caption>',
'<tr><td colspan="2">Expenses:<br>{sromain.nakladyCelk}</td><td colspan="2">Profit:<br>{sromain.ziskCelk}</td><td colspan="2">Revenues:<br>{sromain.prijmyCelk}</td></tr>',
'<tr><td colspan="2">Expenses Not:<br>{sromain.neuhrPrijCelk}</td><td colspan="2">Vat: <br>{sromain.dph}</td><td colspan="2">Revenues Not:<br>{sromain.neuhrVydCelk}</td></tr>',
'</table>',
'<tpl for="branches">',
'<table id="tfhover" class="tftable" style="margin-bottom: 10px;">',
'<caption class="x-panel-header-default"><a href="#{dbName}">{corporation}</a></caption>',
'<tr><td colspan="2">Expenses:<br>{nakladyCelk}</td><td colspan="2">Profit:<br>{ziskCelk}</td><td colspan="2">Revenues:<br>{prijmyCelk}</td></tr>',
'<tr><td colspan="2">Expenses Not:<br>{neuhrPrijCelk}</td><td colspan="2">Vat: <br>{dph}</td><td colspan="2">Revenues Not:<br>{neuhrVydCelk}</td></tr>',
'</table>',
'</tpl>',
'</div>',
'</tpl>'
),
multiSelect : true,
trackOver : true,
deferEmptyText : false,
emptyText : 'No data',
itemSelector : 'div.row'
}
]
});

I had to make a few changes to get it to work like removing the translation vars and the store instantiation. But notice the changes. Now I got this:

41749

sveatlo
8 Feb 2013, 11:02 PM
Thanks for respnse.
But I still cannot make the branches tpl work. Is there any solution?