Results 1 to 2 of 2

Thread: load json datas from proxy

  1. #1
    Sencha User
    Join Date
    Sep 2012
    Posts
    1
    Vote Rating
    0
      0  

    Default Unanswered: load json datas from proxy

    Hi all !
    I must loading datas from a WebService in Json format like that :

    Code:
    [
        {
            "CodeMission": "FOVA",
            "Dessertes": [],
            "HeureProbable": "19/09/2012 10:38",
            "HeureTheorique": "19/09/2012 10:38",
            "Numero": "127034",
            "Quai": null,
            "Retard": "00:00",
            "Sens": "P",
            "Voie": "2",
            "VoiePrecedente": null
        },
        {
            "CodeMission": "VOPA",
            "Dessertes": [
                {
                    "CodeTR3A": "BFX",
                    "Nom": "Le Bras de Fer"
                },
                {
                    "CodeTR3A": "EVC",
                    "Nom": "Evry Courcouronnes"
                }
            ],
            "HeureProbable": "19/09/2012 10:47",
            "HeureTheorique": "19/09/2012 10:47",
            "Numero": "126620",
            "Quai": null,
            "Retard": "00:00",
            "Sens": "P",
            "Voie": "A",
            "VoiePrecedente": null
        }
    ]
    So i have my 2 models :

    Code:
                    Ext.define('ChoixTrain', {
                        extend: 'Ext.data.Model',
                        config: {
                            fields:['CodeMission','HeureProbable','HeureTheorique','Numero','Quai','Retard','Sens','Voie','VoiePrecedente'],
                            hasMany: {model: 'Desserte', name: 'Dessertes'},
                            proxy: {
                                type: 'jsonp',
                                autoLoad:true,
                                url: 'https://plop.com/Trainservice.svc/GetListTrainsAtGare/COE',
                                method: 'POST',
                                params: {
                                    username: 'plop',
                                    password: 'plop'
                                },
                                headers: {
                                    'Accept': 'application/javascript'
                                },
                                reader: {
                                    type: 'json',
                                    model: 'ChoixTrain'
                                }
                            }
                        }
                    });
                    
                    Ext.define('Desserte', {
                        extend: 'Ext.data.Model',
                        config: {
                            fields:['CodeTR3A','Nom'],
                             belongsTo: 'ChoixTrain'
    
                        }
                    });


    and 1 store to load and retreive my datas :

    Code:
                    Ext.define('Desserte', {
                        extend: 'Ext.data.Model',
                        config: {
                            fields:['CodeTR3A','Nom'],
                             belongsTo: 'ChoixTrain'
    
                        }
                    });
                    
                    var trains = Ext.create('Ext.data.Store', {
                        model: 'ChoixTrain'
                    });
                    
                    trains.load({
                        callback: function() {
                            //the user that was loaded
                            var premierTrain = trains.first();
    
                            console.log("Premier Train : " + premierTrain)
                        }
                    });
    with the debuger I see my json string added as a script, so the webservice response is OK, but my "firstTrain" is undefined, and "trains" datas is empty !

    what the problem in my code ?

    Edit : I think the problem comes from my callbackKey, i have a script like "https://plop.com/..../...?callback=Ext.data.JsonP.callback1, but how can i acces to my data list now ?

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,318
    Answers
    3883
    Vote Rating
    1291
      0  

    Default

    Is the JSON that is returned in JSONP format?
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    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.

Tags for this Thread

Posting Permissions

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