【问题标题】:Render nested array of Hashmaps with the usage of "@select" in .dust file在 .dust 文件中使用“@select”渲染嵌套的 Hashmap 数组
【发布时间】:2017-10-27 12:29:15
【问题描述】:

我的 JSON 对象包含 Hashmaps 数组:

{   "someparentkey": {
        "arraykey": [
            {
                "uniquekey": "key1",
                "content": "param1"
            },
            {
                "uniquekey": "key2",
                "content": "param2"
            }
        ]
    }
}

基于"uniquekey"的每个值,我想渲染单独的灰尘模板,其值为"content"传递给导入的灰尘模板。

这是我的基本模板现在的样子:

{#someparentkey}
    {#arraykey}
        {@select key={uniquekey} }
            {@eq value="key1"}{>"path/to/dust1" param={content} /}{/eq}
            {@eq value="key2"}{>"path/to/dust2" param={content} /}{/eq}
            {@default}<!-- Invalid script tag {key} in configuration -->{/default}
        {/select}
    {/arraykey}
{/someparentkey}

我导入的模板(“path/to/dust1.dust”和“path/to/dust1.dust”)如下:

<span>{param}</span>

但在执行灰尘文件的 “grunt build” 时,我收到以下错误:

SyntaxError: arraykey 的预期结束标记,但未找到。在第 3 行,第 9 列 块引用

警告:Dust.js 无法编译模板“path/to/my/base-dust”。

问题:

  1. 我当前的模板代码有什么问题?
  2. 还有没有更好的方法来实现我想要的?

【问题讨论】:

    标签: javascript html node.js gruntjs dust.js


    【解决方案1】:

    这是我最终使用的模板,它对我有用:

    {#someparentkey.arraykey}
        {@select key=uniquekey }
            {@eq value="key1"}{>"path/to/dust1" param=content /}{/eq}
            {@eq value="key2"}{>"path/to/dust2" param=content /}{/eq}
            {@default}<!-- Invalid script tag {key} in configuration -->{/default}
        {/select}
    {/someparentkey.arraykey}
    

    【讨论】:

      猜你喜欢
      • 2018-03-05
      • 2016-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-14
      • 2018-08-12
      • 2019-05-12
      • 1970-01-01
      相关资源
      最近更新 更多