javascript - 将事件监听器添加到 ListView 中的按钮 - WinJS

标签 javascript html windows-8 winjs

我在包含按钮的 ListView 中有一个项目列表。我找不到向按钮添加事件监听器的方法...


这是代码:

JS:

downloadsListView = document.getElementById('downloads').winControl
downloadsListView.itemDataSource = JobList.dataSource
downloadsListView.onloadingstatechanged = function() {
      var _this = this;
      return WinJS.Utilities.query("button.play_pause_button", document.getElementById('downloads')).forEach(function(element) {
        console.log(element);
        return element.onclick = _this._play_pause_download;
      });
    };

我可以保证该函数确实通过控制台输出在按钮上循环。但是点击按钮不会触发任何东西。

我希望有人能提供帮助。谢谢:)

最佳答案

我认为 Dominic 的评论是您最好的选择。 ListView.itemTemplate property MSDN 上的页面说...

Adding interactive elements to an item template The item template can contain most other controls, but it can't contain a FlipView or another ListView.

Normally, when the user interacts with an element, the ListView captures that interaction and uses it to determine whether the user selected or invoked an item or is panning through items. For an interactive element, such as a control, to receive input, you must attach the win-interactive class to the interactive element or one of its parent elements. That element and its children receive the interaction and no longer trigger events for the ListView.

When you attach the win-interactive to an element in a item template, be sure that the element doesn't fill the entire item, otherwise the user won't have a way to select or invoke that item.

To add interactive elements to your item template, you must use a templating function instead of a WinJS.Binding.Template.

关于javascript - 将事件监听器添加到 ListView 中的按钮 - WinJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13785401/

相关文章:

windows - 打开不在同一目录中的文件

javascript - 取消引用变量的闭包有用吗?

javascript - VueJS - 不能在异步函数之外使用关键字 'await'

javascript - 软键盘激活时网页向上滑动

html - 按钮与 div 不对齐

windows-8 - 适用于 Dropbox、EverNote 和 Google Doc (WinRT) 的 SDK

javascript - 使用 Javascript 将链接引用包装为 Ajax 调用

javascript - 轻量级的Web和移动“所见即所得”文本编辑器?

html - 不能使用十六进制代码为 <a> 标记着色?

javascript - 使用库 JSZip 提取 ZIp 文件