Help us understand the problem. What is going on with this article?

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

More than 5 years have passed since last update.

Ractive.jsのハッシュをリストに展開して表示するのはどうするのがスマートなんだろうか?

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

<!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>

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

ishiduca
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
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  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
ユーザーは見つかりませんでした