UWP:如何访问ApplicationData(UWP: How to access ApplicationData)

编程入门 行业动态 更新时间:2024-10-28 04:28:52
UWP:如何访问ApplicationData(UWP: How to access ApplicationData)

我正在尝试在启动时为我的UWP-JS应用程序创建设置值。 我正在关注此文档 。

这是我目前得到的:

(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运行时错误:无法设置未定义或空引用的属性“exampleSetting”

我究竟做错了什么?

I am trying to create a Settings Value for my UWP-JS App on Startup. I am following this Documentation.

Here is what I've currently got:

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

When I start the Application it enters 'Break Mode' with the following exception in line 7 of the given code:

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

What am I doing wrong?

最满意答案

您缺少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之后的属性和方法名称需要以小写字母开头。

You are missing the current property, which is also mentioned in the example you refered to. So your call should be:

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

Edit: The properties and method names after Windows.Storage.ApplicationData need to be start with lowercase.

更多推荐

本文发布于:2023-07-20 11:09:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1198695.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:UWP   ApplicationData   access

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!