locked
Reading from file

    Question

  • I'm writing a gymnastics based app, but I can't seem to work this out.  I have a file which I have written to the following string:

    "glide kip;kip on low bar;images/kip.png;john smith;bars;longkip;kip on high bar;images/kip.png;john smith;bars;"

    My code is supposed to split that string up by the semi-colon and then push every 5 elements of the resulting array into a listview list.

            roamingFolder.getFileAsync("routines.dat").done(
                function (file) {
                    Windows.Storage.FileIO.readTextAsync(file).done(function (fileContent) {
                        var routine = fileContent.split(";");
                        for (i = 0; i < routine.length / 5; i = i + 5) {
                            if (routine[i + 3] == _gymnastName && routine[i + 4] == apparatus) {
                                currentRoutineList.push({ title: routine[i + 3], text: "true", picture: routine[i + 2], gymnast: routine[i + 3], apparatus: routine[i + 4] });
                            } else {
                                currentRoutineList.push({ title: routine[i + 3], text: "false", picture: routine[i + 2], gymnast: routine[i + 3], apparatus: routine[i + 4] });
                            }
                        }
                    });
                });
    

    _gymnastName and apparatus variables have been set earlier in the function (and I know they work), but this for loop is false every time.  What am I missing here? 
    • Changed type Song Tian Friday, November 16, 2012 8:58 AM
    Friday, November 9, 2012 12:38 AM

Answers

  • Hi,

    Please refer to the follow code:

    //var jsonText = JSON.stringify(activitiesArray)
        var jsonText="hey, I am transfered";
    
        var localFolder = Windows.Storage.ApplicationData.current.localFolder;
        //localFolder.createFileAsync("myfile.data", Windows.Storage.CreationCollisionOption.replaceExisting)
        //    .then(function (file) {
        //        return Windows.Storage.FileIO.writeTextAsync(file, jsonText);
        //    });
    
    
        localFolder.getFileAsync("myfile.data")
                        .then(function (file) {
                            return Windows.Storage.FileIO.readTextAsync(file);
                        }).done(function (text) {
                            // activitiesArray = JSON.parse(text);
                            document.getElementById("content").innerHTML=text;
                        });


    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com
    Microsoft One Code Framework

    • Marked as answer by Song Tian Friday, November 16, 2012 8:58 AM
    Friday, November 9, 2012 9:23 AM