Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
OrganizationEventAdvent CalendarQiitadon (β)
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.


Ractive.js で ハッシュをリスト展開して表示するベストプラクティスを教えて下さい


【追記】tekkoc さんに正当な方法を教えてもらいました。 tekkoc さんのコメントを参照ください(2014.02.14)

<!doctype html>
<title>Ractive.js - hash to list</title>
<script src="../bower_components/ractive/Ractive.js"></script>

<main id="main">
<script id="template" type="text/ractive">
    {{# toList(hash) }}
            <span style="font-style: italic;">{{.}}</span>
            <span style="font-weight: bold;">{{hash[.]}}</span>
    {{/ end of hash}}

    {{^ toList(hash) }}
        <h4>no list :(</h4>
    {{/ end of hash}}

var ractive = new Ractive({
    el: 'main'
  , template: '#template'
  , data: {
        hash: {
            a: 'AA'
          , b: 'BB'
          , c: 'CC'
      , toList: function (hash) {
            return Object.keys(hash)


これでも ハッシュのキーと値をリスト表示できるし、ハッシュの値を変更すれば、リスト表示も変わるようになるけど、正当なやり方なんだろうか?

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Help us understand the problem. What are the problem?