View Full Version : Why is the function "load()' from my Model not working?

1 Jul 2014, 10:36 AM

I have a Model defined, which is working really well in a TreePanel and the function save() is also working fine.

I'm trying to make a load() to get a single instance of this model from the database but it seems to not be working.

Here's the piece of code from the error:

var servidor = null;
if (this.editingItem) {
var Servidor = Ext.ModelManager.getModel('MyApp.model.Servidor');
if (Servidor.load) {
console.log('editando'); // prints
console.log(servidor); // prints null
try {
servidor = Servidor.load(this.editingItem.id, {
failure: function() {
console.log('a'); // does not print
success: function() {
console.log('b'); // does not print
callback: function() {
console.log('c'); // does not print
} catch (e) {
console.log(e); // does not print
} else {
servidor = Ext.create('MyApp.model.Servidor');

// a few set operations after this

This code actually generates a GET request to the server, which answers the browser with the following (from the Google Chrome's developer console):

Response Headers:
HTTP/1.0 200 OK
Date: Tue, 01 Jul 2014 18:15:52 GMT
Server: WSGIServer/0.1 Python/2.7.6
X-Frame-Options: SAMEORIGIN
Content-Type: application/json
Access-Control-Allow-Origin: *

{"guid": "{00000000-0000-0000-0000-000000000009}", "parentGuid": null, "name": "A Server", "vendor": "1", "model": "1","address": "","port": 80,"redirect": true,"optimizeBandwidth": true,"reverseConnection": true, "timeOutEnabled": true, "timeOutInterval": 51, "enabledCameras": 1, "contactIdCode": "0001", "contactIdPartition": "", "user": "admin", "password": "", "enabled": false, "connected": false}

And finally the console output:

editando Conexao.js?_dc=1404238545479:286
null Conexao.js?_dc=1404238545479:287
Uncaught TypeError: Cannot read property 'set' of undefined Conexao.js?_dc=1404238545479:307
Uncaught TypeError: Cannot read property 'hasId' of undefined ext-all-dev.js:100280

So everything seems to be working correctly, yet load() assigns undefined to the variable servidor.
What could be wrong?

Gary Schlosberg
11 Jul 2014, 3:51 PM
Sounds a little like this issue:

In which version of ExtJS are you seeing this?

11 Jul 2014, 8:50 PM
Let's clean up a bit first.

You can reduce this:

var Servidor = Ext.ModelManager.getModel('MyApp.model.Servidor');

...down to this:

var Servidor = MyApp.model.Servidor;

Next, what's this if check for?

if (Servidor.load) {

Then we've got a try/catch for no apparent reason.

Then there's this:

servidor = Servidor.load(this.editingItem.id, {

...which seems to be trying to use the return value of load. This won't work, load is asynchronous and won't return anything. My guess is that this is what's causing the first error message.

As for the second error, I think the bug Gary suggested explains why you're getting an error and no callback logging but if everything is configured correctly you shouldn't be hitting that bug anyway. The problem will be somewhere within the config of your model, proxy or reader.