1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Knockout.jsで任意の引数とイベント発生タグの情報使用を同時に行いたい

Posted at

Knockout.jsで任意の引数とイベント発生タグの値を同時に使用したい場合、下記のようにワンクッション入れてやると引数としてイベントハンドラを渡せます。

data-bindの設定(抜粋)

.js_select_purchase(target="#terminal_purchase" data-bind="click: function(data, event){ data.func_1(event,'hoge') }")

viewmodelの定義

class ViewModel
  func_1: (event,arg)=>
    me = $(event.currentTarget)
    # 任意の引数をアラートで表示
    alert(arg)
    # イベントが発生しているタグのvalueを表示
    alert(me.attr('value'))

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?