WinJS.UI.ListView:onItemRevoked - 处理单击

时间:2014-08-19 02:36:25

标签: javascript windows-store-apps

你好。

我无法使此代码正常工作。 基本上它显示我想要的内容并对onClick做出反应,但我不知道如何获得点击项目的名称或任何其他属性。我的普通JS在这里不起作用。 谢谢。

Windows应用商店应用Javascript

=============================================== ===================================

<div id="mediumListIconTextTemplate" data-win-control="WinJS.Binding.Template">
<div style="width: 350px; height: 100px; background:#ffffff; border:1px solid #dbdbdb; border-radius:10px;">
     <!-- Displays the "title" field. -->
     <h4 data-win-bind="innerText: name"></h4>
     <!-- Displays the "text" field. -->
     <h6 data-win-bind="innerText: species"></h6>
</div>
</div>
<div id="listDiv"
      data-win-control="WinJS.UI.ListView"
      data-win-options="{ itemDataSource : dataList.dataSource,itemTemplate: select('#mediumListIconTextTemplate') }"></div>

<script type="text/javascript">

  var dataArray = [
                    { name: "Marley", species: "dog" },
                    { name: "Lola", species: "cat" },
                    { name: "Leo", species: "dog" },
                    { name: "Izzy", species: "cat" },
                    { name: "Ziggy", species: "cat" },
                    { name: "Kanye", species: "fish" }
                ];

      var dataList = new WinJS.Binding.List(dataArray);
      WinJS.UI.processAll();
      WinJS.Utilities.query("#listDiv").listen("iteminvoked", clickHandler, false);

function clickHandler(e) {
console.log(e);
document.getElementById("clickResultDiv").textContent=...GET CLICKED ITEM'S NAME etc...??
}

</script>

1 个答案:

答案 0 :(得分:0)

这将是:

document.getElementById("clickResultDiv").textContent=dataArray[e.detail.itemIndex].name;