【问题标题】:catch the event when listview is rendered WinJS在呈现列表视图时捕获事件 WinJS
【发布时间】:2015-12-12 20:28:21
【问题描述】:

我在 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");

如何在呈现每个输入时捕获该事件,因此我获取所有输入。

【问题讨论】:

  • 这有可能吗?

标签: javascript listview input winjs uwp


【解决方案1】:

我设法找到了解决方案:

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);
            }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-30
    相关资源
    最近更新 更多