0
expressで、express-handlebarsをビューエンジンとして使用し、handlebars helpersで作業しています。私は選択タグのための小さな部分を作成しましたが、文字列としてプレーンキーをレンダリングします。ハンドルバーの部分文字列からオブジェクトキーを解析する方法。
にオブジェクトの配列を渡すマイセレクトパーシャルselect.hbsファイルが
<select name="" id="">
<option value="">Select</option>
{{#forEach this.select_values}}
<option value="{{../this.opt_value}}"> {{ ../this.opt_label }} </option>
{{/forEach}}
</select>
私は怒鳴る使用しています
{{> modules/select select_values=accounts opt_value='name' opt_label='email'}}
レイアウトで
accounts: [
{
name: 'John',
email: '[email protected]'
},
{
name: 'Malcolm',
email: '[email protected]'
},
{
name: 'David',
email: '[email protected]'
}
]
呼び出しパーシャルアカウントそれはハンドルバーbuiltin helper検索 で動作します
"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"
}
例のコードでは、ルックアップヘルパーを使用していません。 – 76484
古い貼り付けの古いコード 正しくなるよ ありがとう – PratapRockerss