gpt4 book ai didi

javascript - UWP:如何访问应用程序数据

转载 作者:行者123 更新时间:2023-12-03 04:56:24 24 4
gpt4 key购买 nike

我正在尝试在启动时为我的 UWP-JS 应用程序创 build 置值。
我正在关注这个Documentation .

这是我目前拥有的:

(function () {
"use strict"

//Initialization
var localSettings = Windows.Storage.ApplicationData.current.localSettings;
// Save value
localSettings.Values["exampleSetting"] = "example";
// Retrieve value
$('p').text(localSettings.Values["exampleSetting"]);
})();

当我启动应用程序时,它进入“中断模式”,但给定代码的第 7 行出现以下异常:

0x800a138f - JavaScript runtime error: Unable to set property 'exampleSetting' of undefined or null reference


我做错了什么?

最佳答案

您缺少 current 属性,您引用的示例中也提到了该属性。所以你的电话应该是:

(function () {
"use strict"

//Initialization
var localSettings = Windows.Storage.ApplicationData.current.localSettings;
// Save value
localSettings.values["exampleSetting"] = "example";
// Retrieve value
$('p').text(localSettings.values["exampleSetting"]);
})();

编辑:
Windows.Storage.ApplicationData后面的属性和方法名称需要以小写字母开头。

关于javascript - UWP:如何访问应用程序数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42416558/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com