最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Saving Local Data in Metro Style App - Stack Overflow

programmeradmin2浏览0评论

I want to make a score mechanism in windows 8 metro style app and want to save that score locally using Windows.Storage.ApplicationData i'm having quite a hard time since im new to visual studio and App building.

var applicationData = Windows.Storage.ApplicationData.current;

var localSettings = applicationData.localSettings;

// Create a simple setting

localSettings.values["totalPike"] = '0';

// Read data from a simple setting

var totalPike = localSettings.values["totalPike"];

if (!totalPike) {
    // No data
}
else {
    // Access data in value
}

// Delete a simple setting

localSettings.values("totalPike");

That is how windows handles app data from msdn

$(document).ready(function () {

        var clicks = 99;

        $("#totalScoreTestButton").click(function () {
            totalPike = totalPike + clicks
            $("#totalScoreTest").text(totalPike);
        });
});

This is the function i use to add the score to the total score preatty basic at the time but whenever i close the app and start it again no score is saved. Can someone help me in this, and if possible explain me how Metro apps handle local data?

I want to make a score mechanism in windows 8 metro style app and want to save that score locally using Windows.Storage.ApplicationData i'm having quite a hard time since im new to visual studio and App building.

var applicationData = Windows.Storage.ApplicationData.current;

var localSettings = applicationData.localSettings;

// Create a simple setting

localSettings.values["totalPike"] = '0';

// Read data from a simple setting

var totalPike = localSettings.values["totalPike"];

if (!totalPike) {
    // No data
}
else {
    // Access data in value
}

// Delete a simple setting

localSettings.values("totalPike");

That is how windows handles app data from msdn

$(document).ready(function () {

        var clicks = 99;

        $("#totalScoreTestButton").click(function () {
            totalPike = totalPike + clicks
            $("#totalScoreTest").text(totalPike);
        });
});

This is the function i use to add the score to the total score preatty basic at the time but whenever i close the app and start it again no score is saved. Can someone help me in this, and if possible explain me how Metro apps handle local data?

Share Improve this question edited Nov 9, 2014 at 21:35 Alen Saqe asked Apr 30, 2012 at 17:52 Alen SaqeAlen Saqe 4797 silver badges26 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

For example:

(function () {
"use strict";

WinJS.Namespace.define("PersistenceManager", {
    stateFile: "game_state",

    saveState: function () {
        var state = {
            game_state: game_state,
            level: levelIndex,
            score: SCORE,
            playerLives: player_lives,
            pLives: p_lives
        };

        WinJS.Application.local.writeText(PersistenceManager.stateFile, JSON.stringify(state));
    },

    loadStateAsync: function () {
        var app = WinJS.Application;

        return app.local.exists(PersistenceManager.stateFile).then(function (exists) {
            if (exists)
                return app.local.readText(PersistenceManager.stateFile).then(function (data) {
                    return JSON.parse(data);
                });
            else return null;
        });
    },

});
})();
发布评论

评论列表(0)

  1. 暂无评论