我有一個類別節點(一個對象數組)。如果product
字段存在,我想打印一個列表項目,如果存在category
字段,則打印另一個列表項目。小鬍子 - 根據嵌套節使用相同名稱
category.nodes = [
{
product: "1",
type: "product"
},
{
product: "2",
type: "product"
},
{
category: "categoryName",
type: "category"
}
]
我的鬍子模板是:
<p>
{{#category.nodes}}
{{#product}}
<li>{{product}}</li>
{{/product}}
{{#category}}
<li>{{category}}</li>
{{/category}}
{{/category.nodes}}
</p>
的{{#category.nodes}} ... {{/category.nodes}}
應該把範圍爲category.nodes section,並且部分
「渲染文本塊一次或多次,這取決於當前上下文中的密鑰的值「
文件的狀態在上false values and empty lists如下:
「如果對方鍵不存在,或存在並具有空,不確定的,虛假的,0,或NaN的值,或者是空字符串或空列表中,該塊將不會被渲染」
This jsFiddle證明一個問題,當嵌套值是相同的父值({{#category}}...{{/category}}
指全球category
,而不是category.nodes.category。)
我想知道是否有某種方式指定哪個category
被引用,因爲這會造成嵌套問題。
This jsfiddle是通過更改父母的名稱來解決問題的方法,我想知道是否有某種方法來指定哪個category
被引用,而不是重命名變量。
問題是當該部分沒有category
時打印{{#category}}...{{/category}}
。
考慮在github上打開一個問題,因爲它似乎是一個錯誤 – moondaisy
(對於那些接下來的)我已經打開了一個[issue](https://github.com/janl/mustache.js/issues/629),我當我收到作者的回覆時會更新=) – Hodrobond