Results 1 to 2 of 2

Thread: Loading a single entity with a store or directly with a model ?

  1. #1
    Ext JS Premium Member
    Join Date
    Jun 2011
    Vote Rating

    Question Loading a single entity with a store or directly with a model ?

    In ExtJs 4 you can define a proxy on a Store or directly in a Model. For collections the obvious solution will be to load data using a Store but when you have a single entity that needs to be loaded from the server side you can do this with a model Model or with a Sotre.

    If we look in the examples from data guide (
    Ext.define('User', {
        extend: '',
        fields: ['id', 'name', 'age', 'gender'],
        proxy: {
            type: 'rest',
            url : 'data/users',
            reader: {
                type: 'json',
                root: 'users'
    User.load(1, {
        success: function(user) {
            console.log("Loaded user 1: " + user.get('name'));
    we will see that we have this convenient static method ("load( Number id, [Object config] ) : void STATIC") that accepts also the ID of the object that will be loaded,and that will pas this ID as a parameter to the request

    When we want to load a single entity form the server via a Store that has the same Proxy and the same model associated, the load method ("load( Object/Function options ) : void") is not accepting any more an ID as a parameter, and you have to pass the ID as a external param to the config element (something like store.load({params : {id:1}})).

    Why this two "load" methods are not providing also similar interfaces (they have similar functionality, they can load a single entity using the attached Proxy) ?

    What is the recommended approach or pattern for loading a single entity form the server?

    Thank you in advance.

  2. #2
    Ext JS Premium Member
    Join Date
    Sep 2007
    Vote Rating

    Default model / store

    I define the proxy on the store, use same model sometimes for different stores and then use proxy.extraParams to set additional post/get params before calling store load.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts