2015-09-16 47 views
1

我在WinJS中有單頁面應用程序。在default.html(這是默認頁面)我有div我從同一目錄呈現其他頁面。在列表視圖呈現時捕獲事件WinJS

<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文件I調用函數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); 
      } 
}