Question

I created a model which contains a proxy to load a single record and its takes no params. I don't want to use a store since I'll never have more then one record. I create an instance of the Model but can't figure out how to tell it to call and load the record from the server. This is the only example I could find, but I don't have an id to pass.

User.load(123, {
success: function(user) {
    console.log("Loaded user 123: " + user.get('name'));
}
});

Also I'm making and ajax call and not a rest call in case that matters.

Was it helpful?

Solution

The load(id, [config]) is static and will return provide you with a new record instance. It uses the proxy that was set via setProxy(proxy) (also static). Per default it will send a read request with the params id: 123. The static method allows you to set some default callbacks within the optional config object. These callbacks are needed to get the instance of the loaded record (or the error).

How it works

// create a Model class
Ext.define('MyApp.User', {
    extend: 'Ext.data.Model',
    fields: [
        {name: 'id', type: 'int'},
        {name: 'name', type: 'string'}
    ]
});

// apply a proxy instance
MyApp.User.setProxy(/*YourAjaxProxy*/);

// prepare a handler
var cb = function(model, op) {
    // log the new model instance
    console.log(model);
};

// get a instance
MyApp.User.load(123, {
    scope: this, // should be the scope of the callback (cb)
    success: cb
});

Not what you need? Just comment...

OTHER TIPS

Just make an Ajax request and store the result in a variable.

 Ext.Ajax.request({
                    url: '/data/get',
                    method: 'GET',
                    params: {
                        requestID: 'XXXX',
                        connName: 'yyyy'
                    },
                    success: function (responseData) {
                       var countResult = Ext.decode(responseData.responseText);                      }
                });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top