gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 23:08:17 24 4
gpt4 key购买 nike

我在包含按钮的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com