侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

[riot.js] 如何向子Tag传递父Tag中的数据

2024-05-13 星期一 / 0 评论 / 0 点赞 / 101 阅读 / 1192 字

使用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

广告 广告

评论区