使用riot遇到一个问题,如以下示例:<html> <head> <title>Riot Demo</title> </head> <body> <script type="riot
使用riot遇到一个问题,如以下示例:
<html> <head> <title>Riot Demo</title> </head> <body> <script type="riot/tag"> <cards> <ul> <card each={opts.items} data={this} width={parent.opts.items.length}></card> </ul> </cards> <card> <li class="card">{opts.data.name}-{opts.width}</li> </card> </script> <cards></cards> <script src="bower_components/riot/riot+compiler.min.js"></script> <script> riot.mount('cards', {'items':[{name:'abc'}, {name:'def'}]}) </script></html>
当我想在 card
中使用父标签的 items.length
时如何处理。这里我使用了 parent.opts.items.length
,即parent不能省。
BTW:
this
指当前的循环变量。- 循环如何指定非this的循环变量,可以
each = {item in items}
,后面可以使用item