1. #1
    Sencha User
    Join Date
    Jun 2012
    Posts
    18
    Answers
    2
    Vote Rating
    1
    neoraptor is on a distinguished road

      0  

    Default Answered: Build a view from json data & have 2 proxies in one store

    Answered: Build a view from json data & have 2 proxies in one store


    Hello,

    First question
    I would like to build a view from data comming from JSON.
    I intended to store the json data into a model (and cache it) and then build the view from the model.

    Is it possible to do?


    Second question
    I have the following json:
    Code:
    {
        "data":[{"name":"Alice","age":"25"},{"name":"Bob","age":"35"},{"name":"Cedric","age":"45"},{"name":"Delphine","age":"55"},{"name":"Eleonore","age":"65"}],
        "ui":{"button":123,"age":1234}
    }
    How could I retrieve the data field and the ui field and store each of them in a separate model?
    I tried to do it with 2 proxies with different rootProperty, but only the latest one is considered.
    Code:
        proxy: {        type: 'ajax',
            //url : 'http://localhost:8888/patientData.json',
            url : 'http://localhost:8888/test.php', // with data & ui
            reader: {
                type: 'json',
                model: 'PhoneGap.model.patientUI',
                rootProperty: 'ui'
            }
        },
    
    
        proxy: {
            type: 'ajax',
            url : 'http://localhost:8888/test.php', // with data & ui
            reader: {
                type: 'json',
                model: 'PhoneGap.model.patientModel',
                rootProperty: 'data'
            }
        },
    Thank you for your support,

  2. First question: Yes you can.

    Second question: of course that is not going to work, you can't have an object with duplicate properties.

    Here is how you can get the ui property:

    Code:
    Ext.define('ModelA', {
        extend : 'Ext.data.Model',
    
        config : {
            fields : [
                'name',
                'age'
            ]
        }
    });
    
    Ext.define('ModelB', {
        extend : 'Ext.data.Model',
    
        config : {
            fields : [
                'button',
                'age'
            ]
        }
    });
    
    Ext.define('Store', {
        extend : 'Ext.data.Store',
    
        config : {
            uiProperty : 'ui',
            model      : 'ModelA',
            proxy      : {
                type    : 'ajax',
                url     : 'data/json.json',
                reader  : {
                    rootProperty : 'data'
                }
            }
        },
    
        getUI : function() {
            var reader  = this.getProxy().getReader(),
                rawData = reader.rawData,
                fn      = reader.createAccessor(this.getUiProperty());
    
            return fn(rawData);
        }
    });
    And the instance:

    Code:
    new Store({
        autoLoad  : true,
        listeners : {
            load : function(store, recs) {
                var ui = store.getUI();
    
                console.log(ui);
            }
        }
    });

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,754
    Answers
    3462
    Vote Rating
    827
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    First question: Yes you can.

    Second question: of course that is not going to work, you can't have an object with duplicate properties.

    Here is how you can get the ui property:

    Code:
    Ext.define('ModelA', {
        extend : 'Ext.data.Model',
    
        config : {
            fields : [
                'name',
                'age'
            ]
        }
    });
    
    Ext.define('ModelB', {
        extend : 'Ext.data.Model',
    
        config : {
            fields : [
                'button',
                'age'
            ]
        }
    });
    
    Ext.define('Store', {
        extend : 'Ext.data.Store',
    
        config : {
            uiProperty : 'ui',
            model      : 'ModelA',
            proxy      : {
                type    : 'ajax',
                url     : 'data/json.json',
                reader  : {
                    rootProperty : 'data'
                }
            }
        },
    
        getUI : function() {
            var reader  = this.getProxy().getReader(),
                rawData = reader.rawData,
                fn      = reader.createAccessor(this.getUiProperty());
    
            return fn(rawData);
        }
    });
    And the instance:

    Code:
    new Store({
        autoLoad  : true,
        listeners : {
            load : function(store, recs) {
                var ui = store.getUI();
    
                console.log(ui);
            }
        }
    });
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  4. #3
    Sencha User
    Join Date
    Jun 2012
    Posts
    18
    Answers
    2
    Vote Rating
    1
    neoraptor is on a distinguished road

      0  

    Default


    Thank you for your answer !!

    However, in your example you only retrieve the model A from the JSON.
    How to retrieve model A & B from JSON data and store them? Do I need to use 2 stores?
    Or should I use 1 main model that has 2 submodel (ui and data)?

  5. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,754
    Answers
    3462
    Vote Rating
    827
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    My example you get the object from the ui root, therefore you can create a new model with that object, gotta leave something for you to do
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  6. #5
    Sencha User
    Join Date
    Jun 2012
    Posts
    18
    Answers
    2
    Vote Rating
    1
    neoraptor is on a distinguished road

      0  

    Default


    Thank you.
    I managed to do it meanwhile

Thread Participants: 1

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi