LoginSignup
0
1

More than 5 years have passed since last update.

riot.js eachにおける自分自身の参照の仕方

Last updated at Posted at 2018-04-09

2通り。eachで指定した要素、イベントから降りてくるitem(riotが定義)。

console.log(this.user,ev.item.user)

それでもわからない場合は parent かevを確認。

console.log('more',this.parent,ev)

全部

<script src="//gnjo.github.io/riot.js"></script>
<loop></loop>
riot.tag(`loop`
,`<ul><li each="{ user in users }" onclick={click}>{user.id}</li></ul>`
,function (opts){
 let f=()=>{return Math.random().toString(36).slice(-8)}
 ,ary= this.users = [
  { name: 'Gian', id:f()},
  { name: 'Dan', id:f()},
  { name: 'Teo', id:f()}
 ]
 click=function(ev){console.log(this.user,ev.item.user); console.log('more',this.parent,ev) }
})
riot.mount('loop')
;
0
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
0
1