Skip to content

Instantly share code, notes, and snippets.

@ishiduca
Last active August 29, 2015 13:56
Show Gist options
  • Save ishiduca/9029805 to your computer and use it in GitHub Desktop.
Save ishiduca/9029805 to your computer and use it in GitHub Desktop.
Ractive.js で ハッシュをリスト展開して表示するベストプラクティスを教えて下さい ref: http://qiita.com/ishiduca/items/b893063a9bc259a47808
<!doctype html>
<head>
<title>Ractive.js - hash to list</title>
<script src="../bower_components/ractive/Ractive.js"></script>
</head>
<body>
<main id="main">
<script id="template" type="text/ractive">
<h2>ハッシュのリスト表示</h2>
<ul>
{{# toList(hash) }}
<li>
<span style="font-style: italic;">{{.}}</span>
:
<span style="font-weight: bold;">{{hash[.]}}</span>
</li>
{{/ end of hash}}
{{^ toList(hash) }}
<h4>no list :(</h4>
{{/ end of hash}}
</ul>
</script>
</main>
<script>
var ractive = new Ractive({
el: 'main'
, template: '#template'
, data: {
hash: {
a: 'AA'
, b: 'BB'
, c: 'CC'
}
, toList: function (hash) {
return Object.keys(hash)
}
}
})
</script>
</body>
<!doctype html>
<head>
<title>Ractive.js - hash to list</title>
<script src="../bower_components/ractive/Ractive.js"></script>
</head>
<body>
<main id="main">
<script id="template" type="text/ractive">
<h2>ハッシュのリスト表示</h2>
<ul>
{{# hash:key }}
<li>
<span style="font-style: italic;">{{key}}</span>
:
<span style="font-weight: bold;">{{.}}</span>
</li>
{{/ hash }}
{{^ hash }}
<h4>no list :(</h4>
{{/ hash }}
</ul>
</script>
</main>
<script>
var ractive = new Ractive({
el: 'main'
, template: '#template'
, data: {
hash: {
a: 'AA'
, b: 'BB'
, c: 'CC'
}
}
})
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment