gpt4 book ai didi

pug - 部分不同于父模板的变量

转载 作者:行者123 更新时间:2023-12-04 06:04:20 25 4
gpt4 key购买 nike

这是我在 index.jade 中的代码:

- each question in questions
- console.log('Question in index.jade: ', question);
!=partial('question', question)

这是我在 question.jade 中的代码:
- console.log('Question in question.jade: ', question);

出于某种原因,两个变量 question是不同的。我在做蠢事吗?

最佳答案

你需要把question键为 question 的对象中的变量并将其传递给偏函数的第二个参数。例如:

- each question in questions
!=partial('question', { question: question })

然后局部 View 将可以访问您想要的问题变量。另外,假设您使用带有 express 的 jade 并且部分是您的 each 中唯一的东西。循环,有一个简写:
!=partial('question', {collection:questions})

这将自动为 questions 中的每个元素渲染一次局部。大批。

关于pug - 部分不同于父模板的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8541090/

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