locked
Save view state Listview in WinJS RRS feed

  • Question

  • Open App -> click on Button -> load data into Listview -> click on item in Listview navigate to another page.

    In new page click back button must click on button and load listview again.

    How i can save any view state when i click Back button no need to load it again ?

    Monday, November 24, 2014 4:28 PM

Answers

  • Well, the "flag" I mentioned here is used to identify whether the user first time visit the page, if user first visit the page, the "flag" should be empty and therefore you let the user clock the button to fill the listview.

    If the user return to current page from another page, there should be a "flag" stored while user leave current page, then you can programmatically insert data to listview.

    I'm not talking about XAML, it's JavaScript logic thing.

    Well, to save a "flag", please ref to the documentation ApplicationData.LocalSettings | localSettings property

    var applicationData = Windows.Storage.ApplicationData.current;
    
    var localSettings = applicationData.localSettings;
    
    // Create a simple setting
    
    localSettings.values["pageVisited"] = "yes";
    
    // Read data from a simple setting
    
    var value = localSettings.values["pageVisited"];
            
    if (!value)
    {
        // No data
    }
    else
    {
        // Access data in value
    }
    
    // Delete a simple setting
    
    localSettings.values.remove("pageVisited");
    

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by nhattuanbl Tuesday, November 25, 2014 8:11 AM
    Tuesday, November 25, 2014 6:43 AM
    Moderator

All replies

  • Hi nhattuanbl,

    Let's say while you click on item and navigate to another page, save some flag in WinJS.Application local/temp object. While back to the page, first check if there is any flag, if there is, load the data programmatically to the listview before the HTML rendered to your user.

    There is no cache in WinJS page, unlike XAML NavigationCacheMode enumeration

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    Tuesday, November 25, 2014 2:10 AM
    Moderator
  • Can you write some code to "save flag" and how to restore it ?

    I'm not learn XAML, javascript only please.

    • Edited by nhattuanbl Tuesday, November 25, 2014 4:45 AM
    Tuesday, November 25, 2014 4:44 AM
  • Well, the "flag" I mentioned here is used to identify whether the user first time visit the page, if user first visit the page, the "flag" should be empty and therefore you let the user clock the button to fill the listview.

    If the user return to current page from another page, there should be a "flag" stored while user leave current page, then you can programmatically insert data to listview.

    I'm not talking about XAML, it's JavaScript logic thing.

    Well, to save a "flag", please ref to the documentation ApplicationData.LocalSettings | localSettings property

    var applicationData = Windows.Storage.ApplicationData.current;
    
    var localSettings = applicationData.localSettings;
    
    // Create a simple setting
    
    localSettings.values["pageVisited"] = "yes";
    
    // Read data from a simple setting
    
    var value = localSettings.values["pageVisited"];
            
    if (!value)
    {
        // No data
    }
    else
    {
        // Access data in value
    }
    
    // Delete a simple setting
    
    localSettings.values.remove("pageVisited");
    

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by nhattuanbl Tuesday, November 25, 2014 8:11 AM
    Tuesday, November 25, 2014 6:43 AM
    Moderator