1. #1
    Ext JS Premium Member
    Join Date
    Jun 2011
    Posts
    14
    Vote Rating
    4
    emilianm is on a distinguished road

      1  

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

    Unanswered: 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 (http://docs.sencha.com/ext-js/4-0/#/guide/data)
    Code:
    Ext.define('User', {
        extend: 'Ext.data.Model',
        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
    Location
    CT
    Posts
    462
    Answers
    1
    Vote Rating
    2
    ValterBorges is on a distinguished road

      0  

    Default model / store

    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.

Thread Participants: 1