最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Event parameter not defined for Knockout click binding using Firefox - Stack Overflow

programmeradmin5浏览0评论

I am getting this JS error: ReferenceError: event is not defined when I try to pass the event object to click binding when I use Firefox 23. Everything works fine under Chrome

Here the code:

<!-- ko foreach: entries -->
   <tr data-bind="click: function(){ $parent.expandRow($data, event) }">
      ...
   </tr>
<!-- /ko -->


vm.entries.expandRow = function(entry, event){
    ...           
}

I am getting this JS error: ReferenceError: event is not defined when I try to pass the event object to click binding when I use Firefox 23. Everything works fine under Chrome

Here the code:

<!-- ko foreach: entries -->
   <tr data-bind="click: function(){ $parent.expandRow($data, event) }">
      ...
   </tr>
<!-- /ko -->


vm.entries.expandRow = function(entry, event){
    ...           
}
Share Improve this question asked Aug 14, 2013 at 0:55 Marco CMarco C 3,2133 gold badges31 silver badges49 bronze badges 1
  • Just found this stackoverflow./questions/2974601/… probably it is the cause – Marco C Commented Aug 14, 2013 at 0:57
Add a ment  | 

2 Answers 2

Reset to default 15

Here the solution from github./knockout/knockout/issues/752

<!-- ko foreach: entries -->
   <tr data-bind="click: function(data, event){ $parent.expandRow($data, event) }">
      ...
   </tr>
<!-- /ko -->

Under Firefox event is not defined on the window object, instead it needs to be passed to the function.

I know that this is a pretty old question, but still if someone is looking for the answer then I achieved it in the following way:

<div id="this-element" data-bind="click : function(){ $root.clicked(event)}">

</div>

Following code (clicked function) is written in the ViewModel for the page:

this.clicked= function (event) {
    console.log(event.currentTarget.id);
}

Knockout 3.4.2

jQuery 3.2.1

发布评论

评论列表(0)

  1. 暂无评论