我已经实现了 SettingsFlyout。从这个浮出控件的角度来看,我的应用程序从用户(名字)收集了一些信息,并希望将其存储在漫游设置中。此信息在用户单击设置视图的按钮时存储,并在弹出按钮的 beforeShow 事件中检索。这两个事件是在 SettingsFlyout 本身的 ready 函数中设置的,但由于某种原因,这个 ready 函数没有被调用。因此,事件不是结果,也没有被调用。现在让我向您展示代码。这是我在 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" />
</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.
}
});
})();
我在这里做错了什么以及如何准备调用函数?