Last active
August 29, 2015 13:56
-
-
Save ishiduca/9029805 to your computer and use it in GitHub Desktop.
Ractive.js で ハッシュをリスト展開して表示するベストプラクティスを教えて下さい ref: http://qiita.com/ishiduca/items/b893063a9bc259a47808
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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