PDA

View Full Version : MVC architecture, models/view/controllers items not accessible



bsmulders
15 Dec 2011, 10:58 AM
I am currently rewriting my application in an MVC architecture, but I am running into a little bit of a problem.

app.js:


Ext.application({
name: 'CTD',
appFolder: 'ctd',
autoCreateViewport: true,
controllers: ['Trip'],
models: ['Trip'],
stores: [''Trips','TripSummaries'],
views: ['TripList'],
launch: function() {
}
});


ctd/store/Trips.js


Ext.define ('CTD.store.Trips', {
extend: 'Ext.data.Store',
requires: 'CTD.model.Trip',
model: 'CTD.model.Trip',
autoLoad: true,
proxy: {
type: 'ajax',
url: '',
method: 'GET',
reader: {
type: 'json',
root: 'trip'
}
},
});



ctd/model/TripSummaries.js


Ext.define ('CTD.store.TripSummaries', {
extend: 'Ext.data.Store',
requires: 'CTD.model.Trip',
model: 'CTD.model.Trip',
autoLoad: true,
proxy: {
type: 'ajax',
url: 'http://localhost:8888/ctdservice/trips',
method: 'GET',
reader: {
type: 'json',
root: 'trips'
}
},
})



ctd/model/Trip.js


Ext.define ('CTD.model.Trip', {
extend: 'Ext.data.Model',
fields: ['Trip_ID', 'Name', 'URI'],
});


ctd/view/TripList.js


Ext.define('CTD.view.TripList', {
extend: 'Ext.grid.Panel',
alias: 'widget.triplist',
requires: 'CTD.store.TripSummaries',
store: 'TripSummaries',
height: '100%',
width: '100%',
columns: [
.......
],
});


ctd/controller/Trip.js


Ext.define('CTD.controller.Trip', {
extend: 'Ext.app.Controller',
store: 'Trips',
required: 'Trips',
init: function() {
this.control({
'triplist': {
itemclick: this.loadTrip
},
});
},

loadTrip: function(dataview, record, item, index, e) {
/* NOT WORKING */
var store = CTD.store.Trips;

store.proxy.url = record.data.URI;
store.load();
},
});


The data from TripSummaries gets loaded into the TripList perfectly.
What I am trying to accomplish is setting the Trips store's proxy url from the Trip controller's "loadTrip" function.

I have tried 'CTD.store.Trips', 'Trips', 'getTripsStore()', 'CTD.store.Trips()', 'Trips()' but I can't get access to the proxy URL. I could only accomplish "new CTD.store.Trips()" which created a new store object, not exactly what I wanted. Firebug tells me CTD.store.Trips is a "function()", and when I open it, I can't see the "proxy" property.

I am guessing I am failing to initialize the store. Could somebody please push me into the right direction? I'm trying to do everything by convention here, so I'd like to avoid solutions like "Ext.getCmp()".

bsmulders
15 Dec 2011, 12:22 PM
It appears I made a mistake on the controller part, "store" should be "stores", and have [ and ] around the store names. I'll keep you posted.