如何从 handlebars partials 解析对象键。

How to parse object key from handlebars partials.

express with express-handlebars as view engine and handlebars helpers 中工作。我在其中为 select 标签创建了小部分,但它将普通密钥作为字符串呈现。

我的 Select 部分 select.hbs 文件

<select name="" id="">
  <option value="">Select</option>
  {{#forEach this.select_values}}
    <option value="{{../this.opt_value}}"> {{ ../this.opt_label }} </option>
  {{/forEach}}
</select>

账户中传递对象数组

accounts: [
      {
        name: 'John',
        email: 'john@example.com'
      },
      {
        name: 'Malcolm',
        email: 'malcolm@example.com'
      },
      {
        name: 'David',
        email: 'david@example.com'
      }
    ]

在布局中调用局部

{{> modules/select select_values=accounts opt_value='name' opt_label='email'}}

我正在为

使用波纹管依赖项
"dependencies": {
    "body-parser": "~1.18.2",
    "cookie-parser": "~1.4.3",
    "debug": "~2.6.9",
    "express": "~4.15.5",
    "express-handlebars": "^3.0.0",
    "handlebars-helpers": "^0.10.0",
    "hbs": "^4.0.1",
    "morgan": "~1.9.0",
    "serve-favicon": "~2.4.5"
  }

它适用于把手 builtin helper lookup 添加了来自车把的默认 {{#each}} 循环。

<select name="" id="">
  <option value="">Select</option>
  {{#each this.select_values}}
    <option value="{{lookup this ../this.opt_value}}"> {{lookup this  ../this.opt_label }} </option>
  {{/each}}
</select>

特别感谢@Tamlyn 对查找助手的解释。