Riotjs-loops

提供:Dev Guides
移動先:案内検索

RIOT.JS-ループ

RIOTのプリミティブまたはオブジェクトの配列を反復処理し、外出先でhtml要素を作成/更新できます。 「各」構造を使用して、それを達成できます。

  • Create array -オブジェクトの配列を作成します。
this.cities = [
   { city : "Shanghai" , country:"China" , done: true },
   { city : "Seoul"    , country:"South Korea" },
   { city : "Moscow"   , country:"Russia"      }
];
  • 各属性を追加-「各」属性を使用します。
<ul>
   <li each = { cities } ></li>
</ul>
  • オブジェクトの配列の反復-オブジェクトのプロパティを使用して配列を反復します。
<input type = "checkbox" checked = { done }> { city } - { country }

以下は完全な例です。

custom7Tag.tag

<custom7Tag>
   <style>
      ul {
         list-style-type: none;
      }
   </style>
   <ul>
      <li each = { cities } >
         <input type = "checkbox" checked = { done }> { city } - { country }
      </li>
   </ul>
   <script>
      this.cities = [
         { city : "Shanghai" , country:"China" , done: true },
         { city : "Seoul"    , country:"South Korea" },
         { city : "Moscow"   , country:"Russia"      }
      ];
   </script>
</custom7Tag>

カスタム7

<html>
   <head>
      <script src = "https://cdnjs.cloudflare.com/ajax/libs/riot/3.13.2/riot+compiler.min.js"></script>
   </head>
   <body>
      <custom7Tag></custom6Tag>
      <script src = "custom7Tag.tag" type = "riot/tag"></script>
      <script>
         riot.mount("custom7Tag");
      </script>
   </body>
</html>

これにより、次の結果が生成されます–