PDA

View Full Version : Different objects of same class over writing each other



getbogged
27 Apr 2014, 2:46 PM
edit http://jsfiddle.net/zns6B/1/

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.




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


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,
});

getbogged
2 May 2014, 9:23 AM
I made a change to my code and added the columns

modelColumns is an array of objects {text:'seomthing',dataIndex:'something'} and i added an array of fields ['A','B','C'] to add to the model and it does not work. I have also tried without the fields and just the model with incorrect results.




Ext.apply(this,{
columns: modelColumns.columns,
store: this.buildStore('Sc.Model.GameModel',modelColumns.fields),
});



buildStore()



buildStore:function(model,fields){
var newmodel = model;
var cmp = Ext.create('Sc.Store.League.LeagueStore',{
model: newmodel,
fields: fields,
});


return cmp;
},



this does not work either. I also tried adding everything under my initComponent like below. And i still don't get the model to work properly. If i try and generate the two different instances of gridList the second instance will use the first instances model no matter what i have tried so far.




Ext.apply(this,{
columns: [{text:'A',dataIndex:'b'}],
store: Ext.create('Sc.Store.MyStore',{




})
model: 'My.Model.MyModel'
})

getbogged
3 May 2014, 5:58 AM
Would anyone know the answer to this? i made a jsfiddle http://jsfiddle.net/zns6B/1/

Its now failing here Uncaught TypeError: Cannot read property 'fields' of undefined