嗨,我创建了一个随机报价生成器Windows Store应用程序,所有报价都很好地填充了,我唯一遇到的问题是如何使报价每天发生变化,而不是每次从首页转到首页时都进行更改。应用中的第二页,反之亦然。任何帮助或朝着正确方向的观点将不胜感激。
以下是该代码将在Javascript中显示的页面的副本:
// For an introduction to the Page Control template, see the following documentation:
// http://go.microsoft.com/fwlink/?LinkId=232511
(function () {
"use strict";
WinJS.UI.Pages.define("/pages/page2/page2.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.
client.getTable("quotes").read().then(function (q) {
{
var randomquote = Math.round(Math.random() * (q.length));
function printquote() {
output.innerHTML += "<div>" + (q[randomquote].body + "</div>");
}
printquote();
}
}, function (err) { debugger; });
},
unload: function () {
// TODO: Respond to navigations away from this page.
},
updateLayout: function (element) {
/// <param name="element" domElement="true" />
// TODO: Respond to changes in layout.
}
});
})();
最佳答案
就像评论中所说的,在服务器而不是客户端上更改引号更为有意义。
创建一个服务器页面,该页面根据当前日期返回报价。您可以通过多种方式实现该功能,但简单的实现方式是将每个引号在首次创建时添加一个日期,然后仅在该日期中使用。