gpt4 book ai didi

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

转载 作者:数据小太阳 更新时间:2023-10-29 03:57:56 24 4
gpt4 key购买 nike

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

数据结构:

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com