2

I try to get started with ExtJs, and I have quite basic question.
I have a model

Ext.define('Mb.model.User', {
    extend: 'Ext.data.Model',
    fields: [
        { name: 'id', type: 'int' },
        { name: 'name', type: 'string' },
        ...
    ],
    proxy: {
        type: 'ajax',
        url : 'server/gui/getUser.php'
    }
});

getUser.php returns a json string (it is the logged in user, and not a user out of a user table):

{"id":"1","name": ... }

I tried the following to load the data, but I get an error Uncaught TypeError: Object [object Object] has no method 'load'

Ext.define('Mb.Application', {
    ...
    launch: function() {
        ....
        user = Ext.create('Mb.model.User');
        user.load();
    }
});

What is the correct way to load that data ?


An additional question: What is the benefit of using Modelhere ?

Couldn't I do something like this ?

Ext.Ajax.request({
    url: 'server/gui/getUser.php',
    success: function(response){
    var user = Ext.JSON.decode(response.responseText);
    }
});  

2 Answers 2

1

In this case load is a static method. You can load a model from your server by passing the id.

Mb.model.User.load(id, {
    success: function(rec) {
        console.log('loaded', rec.getData());
    }
});

The advantage to using a model is the layer of abstraction, + the extra functionality you get from using a model.

Sign up to request clarification or add additional context in comments.

Comments

1

You can do, but with little changes

myRequest = Ext.Ajax.request({
  url: 'getdata.php',
  method: 'GET',
  callback: function(response) {
    console.log(response.responseText);
  }
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.