在javascript中是否有任何事件只能通过脚本而不是指针或键操作触发? [英] Is there any event in javascript which can only be fired through a script and not by pointer or key actions?
问题描述
我必须在点击Reactive-table中的一个列时将数据上下文传递给表行,找不到这样做,我想知道是否有任何我可以触发的事件我的代码在行上,但用户不能在没有代码访问的情况下执行此操作。
I have to get the data context passed to a table row on clicking on one of its columns in a "Reactive-table", finding no way to do this, I am wondering if there is any event which I can fire in my code on the row, but the user should not be able to do this without the code access.
推荐答案
点击任意在tr的tds中,我将事件冒泡到它的行,向获取的元素添加一个类,然后在该行上触发click()事件,单击后我从tr中删除添加的类。
On click of any of the tds of a tr, I bubble the event to its row, add a class to the obtained element, then fire a click() event on that row, After click I remove the added class from the tr.
"click td": function(event) {
event.stopPropagation();
var tr = Utils.bubbleTo(event.target, "tr");
$(tr).addClass("customClass");
$(tr).click();
$(tr).removeClass("customClass");
//used the row data using, Template.instance().dict.get("data"),which is set in the next method.
},
"click .reactive-table tbody tr.customClass": function clickTr() {
Template.instance().dict.set("data", this);
},
我想要一个只能通过脚本触发的事件的原因是,我不希望用户触发任何tr元素的点击,我应该写一个事件:
The reason I wanted a event which could only be fired through a script was, I didn't want users to fire the click of any of "tr" element, for which I should had written an event:
"click .reactive-table tbody tr": function clickTr() {...}
我没有具体回答这个问题,但我用这种方法解决了我的问题。
This is does not specifically answer the question,I had asked, but I solved my problem using this approach.
这篇关于在javascript中是否有任何事件只能通过脚本而不是指针或键操作触发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!