facebook

JSON file question

💡
Our Forums Have Moved

For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub

  1. MobiOne Archive
  2.  > 
  3. Getting Help – General
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #343257 Reply

    Robert Gardner
    Participant

    I have most of my javascript functions embedded in the apps custom.js file. One of my functions parses a JSON “file”. Right now the JSON is embedded in the custom.js file. The production version of this JSON file will be pretty large and may change from time to time. As such I want to have it as a separate file within the apps folder.

    I dont know how to store the JSON file separately then reference it from within the script…

    Any insight / thoughts?

    Thanks

    #343276

    support-michael
    Keymaster

    Please see this example for how to package a json file in a mobione app and then load it: http://www.genuitec.com/support-genuitec/viewtopic.php?f=14&t=6272

    #343884

    Robert Gardner
    Participant

    Wayne,

    I’m not sure I understand the process. Could you be more explicit using my example code noted? Obviously, the JSON I included is the data currently within my custom_.js file that I want to be a separate file. The build index code will be (and currently is) within my custom_.js file.

    Thank you,

    //
    
    var data = {"a":[
        {"i":"BWI","t":"39.17","g":"-76.66","n":"Baltimore","f":"d"},
        {"i":"HEF","t":"38.72","g":"-77.51","n":"Manassas","f":"d"},
        {"i":"IAD","t":"38.94","g":"-77.45","n":"Dulles","f":"d"},
        {"i":"LCA","t":"34.87","g":"33.62","n":"Cyprus","f":"i"},
        {"i":"YKZ","t":"43.86","g":"-79.37","n":"Toronto","f":"i"},  
    ]};
    
    // searchPropertyName represents the name of the property the search will be performed on
    // make sure the ALL data is also sorted by this column, the algorithm relies on this for performance
    
    var searchPropertyName = "i";    
    var dataIndex = null;
    
    function rebuildIndex(){
        
        dataIndex = [];
        var i = 0;
        var indexLetter;
        while(i < data.a.length){
            var currentLetter = data.a[i][searchPropertyName][0].toUpperCase();
            if(!indexLetter || indexLetter != currentLetter){
                indexLetter = currentLetter;
                dataIndex[currentLetter.charCodeAt(0) - 65] = i;
            }
            
            i=i+1;
        }
      // alert(dataIndex.join()); // test index
    }
Viewing 3 posts - 1 through 3 (of 3 total)
Reply To: JSON file question

You must be logged in to post in the forum log in