9

次のようにループ内でオブジェクトを渡したいと思います。

データ構造:

things = [
      {
          title: 'foo'
        , description: 'bar'
      }
    , {
          title: 'baz'
        , description: 'bam'
      }
];

index.jade:

- for thing in things
    include things-template

上記の形式で、そのインクルードの「ローカル」として何らかのパラメーターを指定できるようにしたいと考えています。

もの-template.jade:

li
  h3 #{title}
  p #{description}

これは可能ですか、それとも別の変数に割り当てて「thing-template」内で参照する必要がありますか?

4

2 に答える 2

3

最新のjadeバージョン(0.27.4)
として、オブジェクト参照を同じ名前のテンプレートとして渡すことができます

for thing in things
  include thing

./thing.jade を、thing.jade のオブジェクトとして自動的にインクルードします

li
  h3 #{thing.title}
  p #{thing.description}
于 2012-09-21T22:18:41.097 に答える
-3

既存のテンプレートを含めたいので、それほど多くはないと思います。case単に玉ブロックを使用しないのはなぜですか?

html
    body
        for thing in things
            case things-template
                when "simple"
                    include simple
                when "complexe"
                    include complexe
                default
                    include simple
于 2012-04-20T08:51:53.217 に答える