1. #1
    Sencha User
    Join Date
    Dec 2011
    Posts
    103
    Answers
    1
    Vote Rating
    0
    mike lebowski is on a distinguished road

      0  

    Default Answered: Problem accessing a local data file using Phonegap and ST 2.0?

    Answered: Problem accessing a local data file using Phonegap and ST 2.0?


    My app is intended to be a phonegap native app, not a web app.

    I have an MVC store object that I wish to populate with a fairly large data set. Rather than inlining the data, I decided to put it into a separate .json file, and put this data file in the www filesystem alongside my model and store js.
    e.g
    www/app/data/FooData.json
    www/app/store/FooStore.js
    www/app/model/FooModel.js

    I try to load this data in the FooStore.js

    Code:
        autoLoad : true,
        proxy: {
            type: 'ajax',
            url: 'app/data/FooData.json'
        }
    This works fine if I run the app as a web project in Chrome with the Ripple Phonegap emulator plugin.
    However, it does not work in the IOS Simulator and infuriatingly there is no visible error message in the xcode console output.

    Is this SUPPOSED to work as I want it in Phonegap? Or am I trying to do something that is known not to work? Is there some Phonegap configuration I need to perhaps set?

  2. Hi Mike,

    You are welcome, I hope it works in your case. I posted the update for Beta 1 in the other thread but maybe is gonna be more useful here:

    The original post:
    http://www.sencha.com/forum/showthre...y-to-read-JSON

    The code:
    As @doncoleman pointed, it's just define another class extending AjaxProxy and overriding createRequestCallback to ignore the success check (reasons explained in the original post). So, the code for Beta 1:

    Code:
    Ext.define('Ext.data.SafariOfflineAjaxProxy', {
        extend: 'Ext.data.proxy.Ajax',
        alias : 'proxy.offlineajax',
    
        // based on AjaxProxy::createRequestCallback
        createRequestCallback: function(request, operation, callback, scope) {        
            var me = this;
    
            return function(options, success, response) {
                var action = operation.getAction(),
                    reader, resultSet;
    
                reader = me.getReader();
    
                try {
                    resultSet = reader.process(response);
                } catch(e) {
                    operation.setException(operation, {
                        status: null,
                        statusText: e.getMessage()
                    });
    
                    me.fireEvent('exception', this, response, operation);
                    return;
                }
    
    
                if (operation.process(action, resultSet, request, response) === false) {
                    this.fireEvent('exception', this, response, operation);
                }
    
                //this callback is the one that was passed to the 'read' or 'write' function above
                if (typeof callback == 'function') {
                    callback.call(scope || me, operation);
                }
    
                me.afterRequest(request, success);
            };
        }
    });
    In the Store:
    Code:
    proxy: {
        type: 'offlineajax',
        url: 'sample.json',
        reader : {
            type : 'json'
        }
    }

  3. #2
    Sencha User
    Join Date
    Dec 2011
    Posts
    103
    Answers
    1
    Vote Rating
    0
    mike lebowski is on a distinguished road

      0  

    Default


    this is driving me nuts. I even wrapped my entire Ext.define('FooModel' block in a try catch and no errors are being caught. I really hate how blind I am with this IOS simulator.

    I have even added a listener to the store load event and output the value of the "successful" boolean param for the load event. In IOS simulator it is false. In Chrome Ripple it is true. So the load is being triggered, and it is failing in IOS but without any other details, I am really stumped and frustrated. It seems like this is the simplest of cases.

    I am listening to the load event and trying to log any info that might be helpful, but of all these event parameters ( store, records, successful, operation, eOpts ) only successful is writeable. It seems that records and operation are not defined, so they provide no helpful information. I was hoping to see some value in operation.hasException() or operation.getError (), but those calls themselves fail.

    I wish there was some debug or trace level for Sencha, I cannot believe how hard it is to find out what is wrong in the simulator as only my explicit console messages are showing up. Is there any trace or debug flag?

  4. #3
    Sencha User
    Join Date
    Dec 2011
    Posts
    103
    Answers
    1
    Vote Rating
    0
    mike lebowski is on a distinguished road

      0  

    Default


    Several more direct questions.

    1) Is what I am trying to do reasonable? It seems to me yes, but maybe i am missing something.
    2) Any suggestions on how to get more run time diagnostic information to help isolate the problem?

  5. #4
    Sencha User
    Join Date
    Dec 2011
    Posts
    14
    Answers
    2
    Vote Rating
    0
    Cromamedia is on a distinguished road

      0  

    Default local JSON

    local JSON


    Hi, I hope this helps: http://www.sencha.com/forum/showthre...776#post724776

  6. #5
    Sencha User
    Join Date
    Dec 2011
    Posts
    103
    Answers
    1
    Vote Rating
    0
    mike lebowski is on a distinguished road

      0  

    Default


    Thanks Cromomedia, will try that later today. Really really appreciate you jumping in to answer this question, as I lost 2 days of work struggling with this.

  7. #6
    Sencha User
    Join Date
    Dec 2011
    Posts
    14
    Answers
    2
    Vote Rating
    0
    Cromamedia is on a distinguished road

      0  

    Default Sencha Touch 2 Beta 1

    Sencha Touch 2 Beta 1


    Hi Mike,

    You are welcome, I hope it works in your case. I posted the update for Beta 1 in the other thread but maybe is gonna be more useful here:

    The original post:
    http://www.sencha.com/forum/showthre...y-to-read-JSON

    The code:
    As @doncoleman pointed, it's just define another class extending AjaxProxy and overriding createRequestCallback to ignore the success check (reasons explained in the original post). So, the code for Beta 1:

    Code:
    Ext.define('Ext.data.SafariOfflineAjaxProxy', {
        extend: 'Ext.data.proxy.Ajax',
        alias : 'proxy.offlineajax',
    
        // based on AjaxProxy::createRequestCallback
        createRequestCallback: function(request, operation, callback, scope) {        
            var me = this;
    
            return function(options, success, response) {
                var action = operation.getAction(),
                    reader, resultSet;
    
                reader = me.getReader();
    
                try {
                    resultSet = reader.process(response);
                } catch(e) {
                    operation.setException(operation, {
                        status: null,
                        statusText: e.getMessage()
                    });
    
                    me.fireEvent('exception', this, response, operation);
                    return;
                }
    
    
                if (operation.process(action, resultSet, request, response) === false) {
                    this.fireEvent('exception', this, response, operation);
                }
    
                //this callback is the one that was passed to the 'read' or 'write' function above
                if (typeof callback == 'function') {
                    callback.call(scope || me, operation);
                }
    
                me.afterRequest(request, success);
            };
        }
    });
    In the Store:
    Code:
    proxy: {
        type: 'offlineajax',
        url: 'sample.json',
        reader : {
            type : 'json'
        }
    }

  8. #7
    Sencha User
    Join Date
    Dec 2011
    Posts
    103
    Answers
    1
    Vote Rating
    0
    mike lebowski is on a distinguished road

      0  

    Default


    one other thing plz. I am a newbie to xcode and ios simulator development. But I am experienced with web dev in general and firebug and chrome dev tools, which are essential to debugging javascript issues on normal web stuff.

    What do you do for Phonegap and IOS simulator development? I find myself reduced to console logging , which feels like 20 years ago stuff. Is there a big obvious solution that I am missing to make development easier? Particularly, i am constantly battling hard to find issues related to javascript formatting, missing commas etc. When i run it i get blank screen and then have to search by eye for problem. Do you recommend any lint tools in the absence of debugging tools?

  9. #8
    Sencha User
    Join Date
    Dec 2011
    Posts
    14
    Answers
    2
    Vote Rating
    0
    Cromamedia is on a distinguished road

      0  

    Default


    Hi, unfortunately there nothing you are missing. As far as I know this is what we have.

    However, there are some tips I found while trying so get more information about errors. I hope they can help you and improve a bit the development:

    1. (Obvious) Include the Sencha Debug JS file. Then pay attention to the Xcode console / Chromebug console.
    2. Use Weinre: http://phonegap.github.com/weinre/
    3. Include this script before any other <script> tag in you index.html:

    HTML Code:
    <script>
            window.onerror = function(error) {
                alert(error);
            };
    </script>
    Hope this helps.

  10. #9
    Sencha User
    Join Date
    Dec 2011
    Posts
    103
    Answers
    1
    Vote Rating
    0
    mike lebowski is on a distinguished road

      0  

    Default


    you know I have been including the sench debug.js file from the beginning but I have never seen any helpful information in the console from it. Almost the only things I see in console are my own messages. I wonder if I am actually getting the intended benefit of the debug.js.

    I wonder if I have screwed up which index.html is actually being picked up by xcode. As per phonegap instructions I put the www folder outside of the phonegap project and then dragged into xcode to create the "symbolic link" effect. However, I noticed the other day that in the case of index.html and phonegap.js, those two files alone were present in both my linked www folder AND in the www folder in the project directory. I don't know how that happened. Then I noticed that changes to the index.html that is showing up in the xcode IDE were having no visible effect on my project runtime. I noticed this when i tried to add that global error handler like you suggest. So now, I am not sure what is going on with that subtlety.

    Anyway, thanks for your super responsiveness.

Thread Participants: 1