dimanche 27 avril 2014

Different objects of same class over writing each other

I am displaying two grids. I have defined the Sc.ListGrid as follows. I have the initComponent changing the Store and Model based on the configs passed to Sc.ListGrid. The Second Sc.ListGrid always uses the first grids model. If i switch them and have leagueList second and leagueHistory first. LeagueList will have leagueHistorys model. I want the them to use the model i have defined instead of using the first model from whatever is created first. FYI both models and stores are basic with only only url changed for stores proxy and different fields for the models. How do i get them to truly create new instances and not use each others components.

Code:



Ext.onReady(function(){


var leagueList = new Sc.ListGrid({
title: 'League <?php echo $leaguename; ?>',
resourceType: "league",
height: 400,
resourceSubType: '<?php echo $resourceSubType; ?>',
resourceId: "<?php echo $id; ?>",
cols: true,
});
leagueList.render('leaguePlayers');

var leagueHistory = new Sc.ListGrid({
title: "<?php echo $leaguename; ?> League History",
resourceType: "league",
resourceSubType: 'history',
resourceId: "<?php echo $id; ?>",
cols: true
});
leagueHistory.render('leagueHistory');


});

ListGrid


Code:



Ext.define('Sc.ListGrid', {
extend: 'Ext.grid.Panel',
title: 'Grid',
store: Ext.data.StoreManager.lookup('defaultStore'),
requires: [// Requires both models and both stores ],
columns: [
{ text: 'id', dataIndex: 'id' },
{ text: 'gamename', dataIndex: 'gamename', flex: 1 },
],
config:{
resourceType: false,
// Assume league with team
resourceSubType: 'team',
resourceId: null,
resourceSubId: null,
cols: null,
parentResource: null,
},
checkRequired: function(){
if(this.resourceType == false || this.resourceId == null ){
throw "A require config is not set.";
}
},
initComponent: function(){

if(this.resourceId == null){
throw "No resourceId";
}
this.checkRequired();

if(this.resourceType == 'team'){
// List The Players
var model = Sc.Model.Team.TeamResourceModel;
var store = new Sc.Store.Team.TeamResourceStore({
model: model,
autoLoad: true
});
this.store = store;
}
else if(this.resourceType == 'league' && this.resourceSubType == 'team'){
// If it is a League full of Teams
var model = Sc.Model.League.LeagueTeamModel;
var store = new Sc.Store.League.LeagueStore({
model: model,
autoLoad: true
});
this.store = store;
}
else if(this.resourceType == 'league' && this.resourceSubType == 'single'){
// If it is a League full
var model = Sc.Model.League.LeagueSingleModel;
var store = new Sc.Store.League.LeagueStore({
model: model,
autoLoad: true
});
this.store = store;
}
else if(this.resourceType == 'league' && this.resourceSubType == 'history'){
// Show the history of the League
var model = Sc.Model.GameModel;
var store = new Sc.Store.League.LeagueStore({
model: model
});
this.store = store;
this.store.getProxy().url = 'index/0/'+this.resourceId;
}
else{
this.store = new Sc.Store.GenericStore({
autoLoad: true
});
}


(this.cols == null ? true : this.setCols() );
this.callParent(arguments);


},
setCols: function(){

var fields = this.getStore().getProxy().getModel().getFields();
var newCols = [];
Ext.each(fields,function(v,i){
var cols = { text: v.name, dataIndex: v.name};
newCols.push(cols);
});
this.columns = newCols;
},
height: 200,
width: 400,
});




Aucun commentaire:

Enregistrer un commentaire