呈现列表视图时捕获事件 WinJS
catch the event when listview is rendered WinJS
我在 WinJS 中有一个单页应用程序。在 default.html(这是默认页面)中,我有 div,我在其中呈现同一目录中的其他页面。
<div id="pagebody"><!--Here is page rendered--> </div>
现在,在该页面(呈现到 div 中)我有 ListView。在 ListView 模板中,对于每个 ListViewItem,我都有输入控件 - checkbox
<input name="ListViewCheckBox" type="checkbox"/> <!--in js I fetch all inputs with name ListViewCheckBox-->
现在,我必须在所有输入都已呈现时捕获事件,以便能够根据 "application state" 对它们执行某项操作。在 default.js 文件中,我调用函数 WinJS.UI.Pages.render()
和 WinJS.UI.processAll()
WinJS.UI.processAll().done(function () {
//if I try to fetch all inputs here, I get list with 0 elements (as expected)
});
WinJS.UI.Pages.render("OtherPage.html", PageBody).done(function () {
//if I try to fetch all inputs here, I get list with precisely one item
//it catches input declared in template
//the problem is that I need input from each listviewitem
//(if there are for example 20 listviewitems, and I need to fetch all 20 inputs)
});
我使用以下代码行获取输入:
var Inputs = document.getElementsByName("ListViewCheckBox");
我怎样才能在呈现每个输入时捕获该事件,所以我获取了所有输入。
我设法找到了解决方案:
WinJS.UI.pages.define("OtherPage.html", {
ready: function (element, options) {
this.listcontrol = element.querySelector("#myList").winControl;
var that = this;
function delayLoad(evt) {
if (that.listcontrol.loadingState !== "itemsloaded") return;
//if your list control has any loading animation
//this listener will catch before it is played,
//if you want after animation is done then put state "complete"
// infinite loop without this line
that.listcontrol.removeEventListener("loadingstatechanged", delayLoad);
var inputs = document.getElementsByName("asd");//grab all inputs
inputs.length;//length is not anymore 1, but number of items in listview
}
this.listcontrol.addEventListener("loadingstatechanged", delayLoad);
}
}
我在 WinJS 中有一个单页应用程序。在 default.html(这是默认页面)中,我有 div,我在其中呈现同一目录中的其他页面。
<div id="pagebody"><!--Here is page rendered--> </div>
现在,在该页面(呈现到 div 中)我有 ListView。在 ListView 模板中,对于每个 ListViewItem,我都有输入控件 - checkbox
<input name="ListViewCheckBox" type="checkbox"/> <!--in js I fetch all inputs with name ListViewCheckBox-->
现在,我必须在所有输入都已呈现时捕获事件,以便能够根据 "application state" 对它们执行某项操作。在 default.js 文件中,我调用函数 WinJS.UI.Pages.render()
和 WinJS.UI.processAll()
WinJS.UI.processAll().done(function () {
//if I try to fetch all inputs here, I get list with 0 elements (as expected)
});
WinJS.UI.Pages.render("OtherPage.html", PageBody).done(function () {
//if I try to fetch all inputs here, I get list with precisely one item
//it catches input declared in template
//the problem is that I need input from each listviewitem
//(if there are for example 20 listviewitems, and I need to fetch all 20 inputs)
});
我使用以下代码行获取输入:
var Inputs = document.getElementsByName("ListViewCheckBox");
我怎样才能在呈现每个输入时捕获该事件,所以我获取了所有输入。
我设法找到了解决方案:
WinJS.UI.pages.define("OtherPage.html", {
ready: function (element, options) {
this.listcontrol = element.querySelector("#myList").winControl;
var that = this;
function delayLoad(evt) {
if (that.listcontrol.loadingState !== "itemsloaded") return;
//if your list control has any loading animation
//this listener will catch before it is played,
//if you want after animation is done then put state "complete"
// infinite loop without this line
that.listcontrol.removeEventListener("loadingstatechanged", delayLoad);
var inputs = document.getElementsByName("asd");//grab all inputs
inputs.length;//length is not anymore 1, but number of items in listview
}
this.listcontrol.addEventListener("loadingstatechanged", delayLoad);
}
}