小胡子部分没有循环传递给它的数据

时间:2018-04-15 17:27:10

标签: json templates mustache partials patternlab.io

我正在使用mustacheenter link description here模式实验室一起从json数据文件中呈现项目列表。鉴于此数据结构:

{
  "states": {
    "dropdown": {
      "items": [
        {
          "title": "CA"
        },
        {
          "title": "OR"
        },
        {
          "title": "TX"
        }
      ]
    }
  },
  "roles": {
    "dropdown": {
      "items": [
        {
          "title": "Mid-level Office Manager"
        },
        {
          "title": "Facility Manager"
        },
        {
          "title": "Resources Coordinator"
        }
      ]
    }
  }
}

如果我在我的部分内执行以下操作:

{{#states}}
  {{#dropdown.items}}{{title}}{{/dropdown.items}}
{{/states}}

这些名字很好。

但如果我这样做:

{{#states}}
  {{> molecules-dropdown-picker(btnDropdownToggleLabel: "OR")}}
{{/states}}

下拉选取器部分具有以下代码:

{{#dropdown.items}}{{title}}{{/dropdown.items}}

它不会渲染。我做错了什么?

1 个答案:

答案 0 :(得分:0)

我通过以下方式解决了这个问题:

JSON:

{
  "states": {
    "inputTextLabel": "State",
    "inputTextName": "address_state",
    "btnDropdownToggleLabel": "OR",
    "dropdownPickerItems": [
      {
        "dropdownItemTitle": "OR"
      },
      {
        "dropdownItemTitle": "TX"
      },
      {
        "dropdownItemTitle": "UT"
      }
    ]
  },
  "roles": {
    "inputTextLabel": "Company Role",
    "inputTextName": "company_role",
    "btnDropdownToggleLabel": "Facility Manager",
    "dropdownPickerItems": [
      {
        "dropdownItemTitle": "Facility Manager"
      },
      {
        "dropdownItemTitle": "Resources Manager"
      },
      {
        "dropdownItemTitle": "Mid-level Manager"
      }
    ]
  }
}

FORM:

{{#states}}
  {{> molecules-dropdown-picker-list}}
{{/states}}

DROPDOWN-PICKER-LIST:

<div class="dropdown-picker js-dropdown">
  <ul class="dropdown-picker__list js-dropdown-list">
    {{#dropdownPickerItems}}
      {{> atoms-dropdown-picker-item}}
    {{/dropdownPickerItems}}
  </ul>
</div>

DROPDOWN-PICKER-ITEM:

<li class="dropdown-picker__item js-dropdown-item">
  {{dropdownItemTitle}}
  <span class="dropdown-picker__selected-check">
    {{> atoms-icon(icon-type: "check-small") }}
  </span>
</li>