问题
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.
回答1:
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);
},
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.
来源:https://stackoverflow.com/questions/36044620/is-there-any-event-in-javascript-which-can-only-be-fired-through-a-script-and-no