locked
Listview data source

    Question

  • I'm creating an app that shows data in a listview. Some data is in JSON file, and that file is a resource in the package. When the app starts, I give user a page to enter her details. I want to add these details in my resource file. Now resource file in package is read-only. So I'm copying that file in localFolder and appending that file with user data. Now I want to load the listview with these new data. But the listview gets old data only. What am I doing wrong with following function?A

    Am I doing this right?

    What is difference between url and URI?

    WinJS.xhr({ url: "ms-appdata:///local/copyDataFile.txt" }).then(function (xhr) {
            var items = JSON.parse(xhr.responseText);
    
            // Add the items to the WinJS.Binding.List
            items.forEach(function (item) {
                console.log(item);  //new data is not shown
                list.push(item);
            });
        });


    sonal

    Tuesday, April 29, 2014 6:38 AM

Answers

  • I'm not sure why it's reading old data, but you might be better off if you read the data from the file, then append it after it's already in memory.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, April 29, 2014 12:16 PM
    Moderator
  • Assuming your WinJS.xhr() request is correctly reading copyDataFile.txt, I have two other suggestions:

    (1) After updating the WinJS.Binding.List, call ListView.itemDataSource to update the ListView's data. For example, if items is the List object, do this:

            lv.itemDataSource = items.dataSource; 

    (2) If that doesn't work, maybe WinJS.xhr() is getting cached data instead of current data. Use "If-Modified" attribute to get around that. For example:

            return WinJS.xhr({
                url: url,
                headers: {
                    "If-Modified-Since": "Mon, 27 Mar 1972 00:00:00 GMT" }
            });


    Tuesday, April 29, 2014 10:12 PM

All replies

  • I'm not sure why it's reading old data, but you might be better off if you read the data from the file, then append it after it's already in memory.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, April 29, 2014 12:16 PM
    Moderator
  • Assuming your WinJS.xhr() request is correctly reading copyDataFile.txt, I have two other suggestions:

    (1) After updating the WinJS.Binding.List, call ListView.itemDataSource to update the ListView's data. For example, if items is the List object, do this:

            lv.itemDataSource = items.dataSource; 

    (2) If that doesn't work, maybe WinJS.xhr() is getting cached data instead of current data. Use "If-Modified" attribute to get around that. For example:

            return WinJS.xhr({
                url: url,
                headers: {
                    "If-Modified-Since": "Mon, 27 Mar 1972 00:00:00 GMT" }
            });


    Tuesday, April 29, 2014 10:12 PM