Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You probably want to use the <code>onItemInvoked</code> event of ListView items.</p> <p>Say, <code>myItemList</code> is the id of your listView element in DOM, not the id of your template</p> <pre><code>&lt;div id="myItemList" class="myItemList" data-win-control="WinJS.UI.ListView" data-win-options="{layout: {type: WinJS.UI.GridLayout, groupHeaderPosition: 'top'}}" aria-label="Collections"&gt; &lt;/div&gt; </code></pre> <p>Here is how you can write this event handler:</p> <pre><code>function myItemInvoked (e) { var ix = e.detail.itemIndex; var myItemList = document.getElementById('myItemList'); if (!myItemList ) { return; } var myItemListControl = myItemList.winControl; var binding = myItemListControl .itemDataSource.createListBinding(); binding.fromIndex(ix).then(function (item) { console.log('invoke ' + item.data.link); binding.release(); // open a browser to navigate to the url Windows.System.Launcher.launchUriAsync(new Windows.Foundation.Uri(item.data.link)) }); } </code></pre> <p>When you <code>updateLayout</code> for your listView (or wherever you bind the datasource to your listview), you can call <code>WinJS.UI.setOptions</code> like this</p> <pre><code>WinJS.UI.setOptions(myItemListControl, { itemDataSource: myItemList.dataSource, itemTemplate: listItemTemplateRenderer, //your template element retrieved by getElementById groupDataSource: null, groupRenderer: null, selectionMode: 'single', oniteminvoked: itemInvoked }); </code></pre> <p>Hope this helps.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload