ネストされたスキーマがあります。{{> afQuickField name='work_item' template="myTemplate"}}
入力を非常に論理的な方法で出力することを使用しますが、私のより複雑なオブジェクトの一部では、これはあまり実用的ではありません。各入力を他の html に正確に配置できるテンプレートを設定したいと思います。
これらは (通常) オブジェクトの配列でもあるため、.autoform-add-item
ボタンの.autoform-remove-item
機能は非常に優れており、維持したいと考えています。
特定のネストされたスキーマのカスタム テンプレートを定義し、メイン フォームで呼び出すにはどうすればよいですか?
試しました
<template name="afWorkItem_myTemplate">
ブートストラップ 3 フォーム テンプレートから外挿されたカスタム フォーム テンプレートのような名前を作成します。私はそれを好きに呼ぼうとしまし{{> afWorkItem name='work_item' template="myTemplate"}}
たが、それはまったく機能しませんでした。
アップデート
afArrayField
に基づいてさまざまな構造を出力するようにカスタム テンプレートを変更しようとしましたarrayFieldName
。これは少し近いように見えましたが、まだ葉巻ではありません。
Template.afArrayField_autoupdate.helpers({
whichTemplate: function(templateName){
return this.arrayFieldName === templateName;
}
});
次にafArrayField_autoupdate
テンプレートで:
{{#if whichTemplate 'address'}}
{{> afQuickField name=this.current.street options=afOptionsFromSchema template="autoupdate" placeholder="schemaLabel"}}
<br />
{{> afQuickField name=this.current.city options=afOptionsFromSchema template="autoupdate" placeholder="schemaLabel"}}
{{> afQuickField name=this.current.state_id options=afOptionsFromSchema template="autoupdate" placeholder="schemaLabel"}}
{{> afQuickField name=this.current.zip options=afOptionsFromSchema template="autoupdate" placeholder="schemaLabel"}}
<br />
{{> afQuickField name=this.current.address_type_id options=afOptionsFromSchema template="autoupdate" placeholder="schemaLabel"}}
{{> afQuickField name=this.current.active_address options=afOptionsFromSchema template="autoupdate" placeholder="schemaLabel"}}
{{else}}
{{> afQuickField name=this.name label=false options=afOptionsFromSchema template="autoupdate" placeholder="schemaLabel"}}
{{/if}}
これは非常に近いものでしたが、すべてのフィールド (else ブロックで afQuickField メソッドを使用するだけで選択されたフィールドを含む) はテキスト入力として出力されました。