简体   繁体   English

Jade Mixin迭代json

[英]Jade mixin iteration json

I have the following json file: 我有以下json文件:

{
  "leadership": [
    {
        "leadername": "Name1",
        "leaderjob": "Chairman",
        "leaderdescription": "The boss"
    },
    {
        "leadername": "Name2",
        "leaderjob": "Chief Executive Officer",
        "leaderdescription": "Other boss"
    }
  ]
}

and if I try to get the content with the following mixin: 如果我尝试使用以下mixin获取内容:

mixin defList(obj)
  dl.deflist
    each item in obj
      dt= item.leadername
      dd= item.leaderdescription

by calling it like this 通过这样称呼它

+defList(leadership)

everything works fine, but what I would like to have is this: 一切正常,但是我想拥有的是:

mixin defList(obj, name, description)
    dl.deflist
        each item in obj
           dt= name
           dd= description

so I would be able to call it like this: 所以我可以这样称呼它:

+defList(leadership, leadername, leaderdescription)

but unfortunately I get only empty dt and dd tags. 但不幸的是,我只有空的dt和dd标签。

Is there any way to make it work and populate the list? 有什么方法可以使其工作并填充列表吗? I can't figure out what am I doing wrong. 我不知道我在做什么错。

If I understood correctly your question, you would solve like this: 如果我正确理解了您的问题,则可以这样解决:

mixin defList(obj, name, description)
  dl.deflist
    each item in obj
      dt= item[name]
      dd= item[description]

then: 然后:

+defList(leadership, "leadername", "leaderdescription")

Result: 结果:

<dl class="deflist"><dt>Name1</dt><dd>The boss</dd><dt>Name2</dt><dd>Other boss</dd></dl>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM