基本上我只想visible:
在我悬停的 div 上启动,但它适用于所有这些,无论我悬停在哪一个上。
我想这是有道理的,因为我绑定到visible:
内部foreach:
循环,所以它适用于所有循环。是否有 KnockoutJS 解决方法,或者我应该使用$jQuery.hover()
它来代替它?
html:
<div>
<div data-bind="foreach: hostGroups">
<div data-bind="css: { style: true }, event: { mouseover: $root.showDeleteLink, mouseout: $root.hideDeleteLink }">
<span data-bind="text: hostName"></span>
<span class="delete-link" data-bind="visible: $root.deleteLinkVisible">this is a delete link</span>
</div>
</div>
</div>
JavaScript:
var data = [
{ "hostName": "server1" },
{ "hostName": "server2" },
{ "hostName": "server3" }
];
var viewModel = {
hostGroups: ko.observableArray(data),
deleteLinkVisible: ko.observable(false),
showDeleteLink: function() {
viewModel.deleteLinkVisible(true);
},
hideDeleteLink: function() {
viewModel.deleteLinkVisible(false);
}
};
ko.applyBindings(viewModel);