【发布时间】:2017-04-25 00:27:17
【问题描述】:
我尝试在 Jekyll 中选择并使用我的导航子树,在 JSON 中指定。
这是文件_data/navigation.json:
{
"main": [
{"text": "a", "children" : [
{"text": "aa" },
{"text": "ab" }
]},
{"text": "b", "children": [
{"text": "ba", "children": [
{"text": "baa" },
{"text": "bab" },
{"text": "bac" }
] },
{"text": "bb", "children": [
{"text": "bba" },
{"text": "bbb" },
{"text": "bbc" }
]},
{"text": "bc", "children": [
{"text": "bca"},
{"text": "bcb"}
]},
{"text": "bd" },
{"text": "be" }
]},
{"text": "d" },
{"text": "e"},
{"text": "f" },
{"text": "g" }
]
}
现在我想得到'b'的子树:
{% assign stuff = site.data.navigation.main | where:"text","b" %}
如果我通过{{ stuff }} 打印此内容,jekyll/liquids 会为我提供以{"text": "b", "children":... 开头的单行字符串表示,正如人们所预料的那样。 {{stuff | size}} 是 1,所以我可以预料,它是一个对象,而不是内部的一系列字符。但是如果我想继续使用这个结构,我没有输出,stuff.text、stuff["text"] 等等都不起作用。
有人给我提示吗?
【问题讨论】: