riot.js eachにおける自分自身の参照の仕方
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')
;
Author And Source
この問題について(riot.js eachにおける自分自身の参照の仕方), 我々は、より多くの情報をここで見つけました https://qiita.com/HadaGunjyo/items/174cb844982f7443351d著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .