我在WinJS中有一个单页应用程序。在default.html(默认页面)中,我有div,我在同一目录中呈现其他页面。
<div id="pagebody"><!--Here is page rendered--> </div>
现在,在那个页面(渲染到该div中)我有ListView。在ListView模板中,对于每个ListViewItem,我有输入控件 - 复选框
<input name="ListViewCheckBox" type="checkbox"/> <!--in js I fetch all inputs with name ListViewCheckBox-->
现在,我必须根据“应用程序状态”,在所有输入都被渲染后才能捕获事件。在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");
如何在渲染每个输入时捕获该事件,因此我将获取所有输入。
答案 0 :(得分:0)
我设法找到解决方案:
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);
}
}