javascript - 如何将对象的属性作为本地属性传递给 Jade 中的包含项?

标签 javascript templates template-engine pug

我想在循环中传递一个对象,如下所示;

数据结构:

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

index.jade:

- for thing in things
    include things-template

在上述格式中,我希望能够将某种参数指定为包含的“本地”。

things-template.jade:

li
  h3 #{title}
  p #{description}

这可能吗,还是我需要将它分配给另一个变量并在我的“事物模板”中引用它?

最佳答案

作为最新的 Jade 版本(0.27.4)
您可以传递与模板同名的对象引用

for thing in things
  include thing

将自动包含 ./thing.jade 并将 thing 作为对象
在 thing.jade 中:

li
  h3 #{thing.title}
  p #{thing.description}

关于javascript - 如何将对象的属性作为本地属性传递给 Jade 中的包含项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10239124/

相关文章:

php - 如何获取来自另一个域的json数据?

javascript - 使用PrototypeJs,如何异步加载jsp页面

c++ - 模板化类中参数包的语法

c++ - 模板错误

template-engine - 为什么 Playframework 2 使用自定义的 Scala 模板引擎而不是以 xml 模式构建的 scalas?

php - 通过 PHP 解析 html <script> 不能完全工作

javascript - 注释 JavaScript 对象和方法的首选方法是什么?

javascript - 从函数返回 Axios Promise

java - 非servlet JSP

javascript - FullCalendar:当 event.Title 相同时阻止重叠