我已经实现了 SettingsFlyout。从这个浮出控件的角度来看,我的应用程序从用户(名字)收集了一些信息,并希望将其存储在漫游设置中。此信息在用户单击设置视图的按钮时存储,并在弹出按钮的 beforeShow 事件中检索。这两个事件是在 SettingsFlyout 本身的准备功能中设置的,但由于某种原因,我遇到了以下错误。
0x800a138f - JavaScript 运行时错误:无法获取未定义或空引用的属性“winControl”
在下一行
var divtest = document.getElementById"test").winControl;
同样我也得到
0x800a138f - JavaScript 运行时错误:无法设置未定义或空引用的属性“onclick”。
你看到我做错了什么导致这些问题吗?
这是我在 default.html 中的内容
app.onsettings = function (e) {
e.detail.applicationcommands = {
"test": {
href: "/pages/settings/test/test.html",
title: "Test"
}
}
WinJS.UI.SettingsFlyout.populateSettings(e);
};
这是 test.html 本身。
<!DOCTYPE html>
<html>
<head>
<title></title>
<link href="/pages/settings/test/test.css" rel="stylesheet" />
<script src="/pages/settings/test/test.js"></script>
</head>
<body>
<div
data-win-control="WinJS.UI.SettingsFlyout" data-win-options="{settingsCommandId:'test', width:'narrow'}">
<div class="win-header">
<div class="win-label">test</div>
</div>
<div class="win-content">
First Name: <input id="firstname" />
<br />
<input type="submit" value="Save" />
</div>
</div>
</body>
</html>
这是 test.js 文件。
(function () {
"use strict";
WinJS.UI.Pages.define("/pages/settings/test/test.html", {
// This function is called whenever a user navigates to this page. It
// populates the page elements with the app's data.
ready: function (element, options) {
// TODO: Initialize the page here.
var roamingSettings = Windows.Storage.ApplicationData.current.roamingSettings;
var divtest = document.getElementById("test").winControl;
var firstname = document.getElementById("firstname");
document.getElementById("submit").onclick = function (e) {
//alert('hi');
roamingSettings.values["firstname"] = firstname.value;
}
divtest.addEventListener("beforeshow", function () {
firstname.value = roamingSettings.values["firstname"];
});
},
unload: function () {
// TODO: Respond to navigations away from this page.
},
updateLayout: function (element, viewState, lastViewState) {
/// <param name="element" domElement="true" />
// TODO: Respond to changes in viewState.
}
});
})();