W3Data オブジェクト

❮ 前章へ 次章へ ❯

オブジェクトの表示

W3Data の目的は、HTML ページ内にデータを表示することです。

W3Data のパワーを実証するために、JavaScript オブジェクト(myObject)を表示してみます。

オブジェクトは、CustomerName、City、Country プロパティを持つ customers オブジェクトの配列です:

myObject

var myObject = {"customers":[
{"CustomerName":"Alfreds Futterkiste","City":"Berlin","Country":"Germany"},
{"CustomerName":"Around the Horn","City":"London","Country":"UK"},
{"CustomerName":"B's Beverages","City":"London","Country":"UK"},
{"CustomerName":"Blauer See Delikatessen","City":"Mannheim","Country":"Germany"},
{"CustomerName":"Bon app'","City":"Marseille","Country":"France"},
{"CustomerName":"Bottom-Dollar Marketse","City":"Tsawassen","Country":"Canada"},
{"CustomerName":"Chop-suey Chinese","City":"Bern","Country":"Switzerland"}
]};

ドロップダウンの充填

<select id="id01">
<option w3-repeat="customers">{{CustomerName}}</option>
</select>

<script>
w3DisplayData("id01", myObject);
</script>
Try It Yourself ❯

リストの充填

<ul id="id01">
  <li w3-repeat="customers">{{CustomerName}}</li>
</ul>

<script>
w3DisplayData("id01", myObject);
</script>
Try It Yourself ❯

チェックボックスの充填

<table id="id01">
  <tr w3-repeat="customers" class="{{Color}}">
    <td>{{CustomerName}}</td>
    <td><input type="checkbox" {{checked}}"></td>
  </tr>
</table>

<script>
w3DisplayData("id01", myObject);
</script> 
Try It Yourself ❯

クラスの充填

<table id="id01">
  <tr w3-repeat="customers" class="{{Color}}">
    <td>{{CustomerName}}</td>
  </tr>
</table>

<script>
w3DisplayData("id01", myObject);
</script>
Try It Yourself ❯

<table id="id01">
  <tr w3-repeat="customers" class="{{Size}}">
    <td>{{CustomerName}}</td>
  </tr>
</table>

<script>
w3DisplayData("id01", myObject);
</script> 
Try It Yourself ❯

テーブルの充填

<table id="id01">
  <tr>
    <th>Customer</th>
    <th>City</th>
    <th>Country</th>
  </tr>
  <tr w3-repeat="customers">
  <td>{{CustomerName}}</td>
  <td>{{City}}</td>
  <td>{{Country}}</td>
  </tr>
</table>

<script>
w3DisplayData("id01", myObject);
</script>
Try It Yourself ❯

❮ 前章へ 次章へ ❯