PDA

View Full Version : Unexpected string on getController



zoga08
31 Oct 2012, 9:35 AM
Hi guys,

I'm new to ExtJs4, but I'm moving fast on my learning. I got stuck at this problem, when I call the method getController to get my controller name dynamically, I got a "Uncaught SyntaxError: Unexpected strind" and I have no idea why, because the method expects a string as parameter.

Here is my code.


listeners: {
itemclick: function(view, record, item, index, evt, options) {
if ( record.get('leaf') ) {
console.log("testing");
console.log(record.raw['controllerName']);
//var controller = iGWSystem.app.getController(record.raw['controllerName']);
var controller = iGWSystem.app.getController('Gateway');
console.log(controller);
controller.init();

var abaAberta = this.ownerCt.down('#tabCenter').items.findBy(function(aba){
return aba.title === record.get('text');
});

if (!abaAberta) {
this.ownerCt.down('#tabCenter').add({
title: record.get('text'),
closable: true,
layout: 'fit',
autoDestroy: true,
items: {
xtype: record.raw['xTypeClass']
}
}).show();
} else {
this.ownerCt.down('#tabCenter').setActiveTab(abaAberta);
}
}
}
},


Any help will be welcome.

skirtle
31 Oct 2012, 10:02 PM
SyntaxError is normally thrown for invalid JavaScript, it doesn't mean you're passing a string when the method is expecting something else.

For example, you'd get that error in Chrome if you write something like this:


function name('hello'){}

I don't see anything syntactically wrong with the code you posted, nor does my IDE. You'll need to dig in with the dev tools to figure out exactly where the error is occurring. Have your debugger break on all errors. In Chrome, go to the Source tab and click on the octagonal pause symbol in the bottom toolbar to have it 'pause on exceptions'. Firebug has similar functionality if you'd rather debug there.

zoga08
1 Nov 2012, 3:41 AM
Thanks skirtle,

I will take a look.

zoga08
6 Nov 2012, 4:42 AM
Hi skirtle,

I tried the "pause on exceptions", but the debug pause at the extjs script "ext-all.js" and its really hard to debug it to find whats happening.

Here's a printscreen of the error.

39857

skirtle
6 Nov 2012, 4:56 AM
Use ext-all-dev.js during debugging, not ext-all.js.

That error message is quite different to the one you reported originally. I suspect we're now fixing a different problem.

Judging by that stacktrace it looks like grabbing the controller is causing it to try to instantiate some stores. That in turn causes their proxies to be created and it looks like there's a missing type for one of those proxies.

All of this implies that your controller isn't being created until you call getController. That's a bad sign, it suggests you're synchronously loading the controller at that point.

zoga08
6 Nov 2012, 5:40 AM
The error message with the ext-all-dev.js is a lot better, but I'm new at ExtJs and I cant figure it out what is wrong.

Here's the error message.

Uncaught Error: [Ext.createByAlias] Cannot create an instance of unrecognized alias: proxy.undefined

But I havent nothing called proxy.

skirtle
6 Nov 2012, 9:11 AM
Try to isolate the problem further.

It seems to be caused by one of the stores for that controller. So the first thing to do is to establish which store is causing the problem. Remove all the stores from the stores config and add them back in one by one until you figure out which store is causing the problem.

Once you've found the guilty store, take a look at the proxy config for that store.

zoga08
6 Nov 2012, 9:50 AM
I only have one store.

this is my store.



Ext.define('IGWSystem.store.Gateways',{
extend: 'Ext.data.Store',
model: 'IGWSystem.model.Gateway',
autoLoad: true,
pageSize: 15,
//autoLoad: { start: 0, limit: 15 },
proxy: {
api: {
read: 'app/data/php/gateway/listaGateways.php'
},
actionMethods: {
read: 'POST'
},
reader: {
type: 'ajax',
root: 'gateways',
successProperty: 'success'
}
}
});


and this is my model



Ext.define('IGWSystem.model.Gateway',{
extend: 'Ext.data.Model',
fields: [{
name: 'id'
},{
name: 'cifraGuia',
type: 'string'
},{
name: 'ipGateway',
type: 'string'
},{
name: 'descricao',
type: 'string'
}]
});


and this is my controller



Ext.define('IGWSystem.controller.Gateways',{
extend: 'Ext.app.Controller',
stores: ['Gateways'],
models: ['Gateway'],
views: [
'gateway.List'
],
refs: [{
ref: 'gatewayList',
selector: 'gatewaylist'
}],


init: function() {
this.control({
'gatewaylist': {
itemdbclick: this.edit
}
});
},
edit: function(){
console.log('Double Click Test');
}
});


i cant find anything wrong with them

skirtle
6 Nov 2012, 10:53 AM
You've got your types in a muddle:


Ext.define('IGWSystem.store.Gateways',{
...
proxy: {
type: 'ajax',
...
reader: {
type: 'json',
...
}
}
});

zoga08
7 Nov 2012, 3:46 AM
Thanks skirtle,

it was a terrible mistake, everything is working now.

Thanks