LoginSignup
9
9

More than 5 years have passed since last update.

Riotjsで任意の回数だけループさせる

Last updated at Posted at 2016-06-11

何かのリストがあって最初は上から3件だけを表示させ、「一覧を見る」みたいなボタンをクリックするとリストの全部を表示させる。みたいなSPAのサイトを作るときのメモ。

 eachの後にifをいれる。

eachでループ処理する際に、ループする回数が取得できる。
ループ回数がiに入ってくるので、それをifで判定してあげる。

<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>

<app></app>

<script type="riot/tag">
<app>
    <ul>
        <li each={ t, i in this.arr } if={ i < 3 }>{ t.text }</li>
    </ul>
    this.arr = [
        {text:"1つめ"},
        {text:"2つめ"},
        {text:"3つめ"},
        {text:"4つめ"},
        {text:"5つめ"},
    ]
</app>
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/riot/2.3.11/riot+compiler.min.js"></script>
<script>riot.mount('*')</script>
</body>
</html>
9
9
1

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
9
9