Templates 自定义Meteor自动表单模板
我有嵌套的模式。使用Templates 自定义Meteor自动表单模板,templates,meteor,meteor-autoform,Templates,Meteor,Meteor Autoform,我有嵌套的模式。使用{{>afQuickField name='work\u item'template=“myTemplate”}以一种非常合乎逻辑的方式输出输入,但是对于我的一些更复杂的对象来说,这并不是非常实用。我想建立一个模板,在这个模板中,我可以精确地将每个输入与其他html放在一起 这些也是(通常)对象数组,因此.autoform add item和.autoform remove item按钮功能非常好,我想保留它 如何为特定嵌套模式定义自定义模板并在主窗体中调用它们 已经尝试过了
{{>afQuickField name='work\u item'template=“myTemplate”}
以一种非常合乎逻辑的方式输出输入,但是对于我的一些更复杂的对象来说,这并不是非常实用。我想建立一个模板,在这个模板中,我可以精确地将每个输入与其他html放在一起
这些也是(通常)对象数组,因此.autoform add item
和.autoform remove item
按钮功能非常好,我想保留它
如何为特定嵌套模式定义自定义模板并在主窗体中调用它们
已经尝试过了
创建一个名为“我的自定义表单模板”的
,该模板是从bootstrap3表单模板中推断出来的。然后我试着像{>afWorkItem name='work\u item'template=“myTemplate”}}
那样调用它,但这根本不起作用
更新
我试图修改我的自定义afArrayField
模板,以基于arrayFieldName
输出不同的结构。这似乎有点接近,但仍然没有雪茄
Template.afArrayField_autoupdate.helpers({
whichTemplate: function(templateName){
return this.arrayFieldName === templateName;
}
});
然后在afArrayField\u 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}}
{{{#如果模板“地址”}
{{>afQuickField name=this.current.street options=a选项fromschema template=“autoupdate”placeholder=“schemaLabel”}
{{>afQuickField name=this.current.city options=afOptionsFromSchema template=“autoupdate”placeholder=“schemaLabel”}
{{>afQuickField name=this.current.state\u id options=a选项fromschema template=“autoupdate”placeholder=“schemaLabel”}
{{>afQuickField name=this.current.zip options=a选项fromschema template=“autoupdate”placeholder=“schemaLabel”}
{{>afQuickField name=this.current.address\u type\u id options=a选项fromschema template=“autoupdate”placeholder=“schemaLabel”}
{{>afQuickField name=this.current.active\地址选项=a选项fromschema template=“autoupdate”placeholder=“schemaLabel”}
{{else}
{{>afQuickField name=this.name label=false options=a选项fromschema template=“autoupdate”placeholder=“schemaLabel”}
{{/if}
这非常接近,但我的所有字段(包括如果我在else块中简单地使用afQuickField方法,则选择的字段)都作为文本输入 如果您试图添加自定义的
afWorkItem
输入类型,您必须调用以让AutoForm知道它。不确定模板完全不工作的确切含义,但这可能是一个原因。当您尝试创建自定义的afWorkItem
输入时,有大量的示例以。的形式出现,您是否打电话让AutoForm知道了这一点?@mark确实是这样做的。我不得不单独创建html/js,因为该包还不兼容autoform 5.0+。我将在稍后发布,我确实做到了这一点,虽然有点黑客。哦,好的。可能有一种非黑客的方式来做你想做的事情,但我不确定你已经尝试了什么,所以我会等待你的更新。非常奇怪的是,它们显示为else
块中的select输入,而不是if
块中的select输入。。。您还可以尝试其他一些有趣的事情:在afArrayField
模板中,如果您将type=“select”
添加到afQuickField
s,或者将其更改为afSelect
s,会发生什么?马克实际上,我已经将此问题与我问过的另一个问题混淆了,可能是在我深夜开发太长的迷雾中。你的建议似乎恰到好处,我还没有打电话给addInputType。我今天要试试。请在回答中建议!没问题,我经常这样。我已经发布了一个答案——祈祷成功!如果您查看afArrayField
,我不想丢失使用该模板的许多功能(基本上是添加/删除数组元素)。我真的很想改变它叫“afQuickField”的地方,所以我想一定有办法改变选择哪个模板,这样我就可以在afArrayField
one中使用我的自定义模板如果我没弄错的话,你是在尝试显示包含afquickfields的选择字段。您是否尝试添加type=select或同时使用afSelect?我正在尝试。。。在afArray模板内显示表单部分(某些嵌套模式)的自定义布局,通常仅根据嵌套模式输出表单输入。这是因为我可以控制HTML,我有其他我想要的HTML元素,它们不会自动输出,而且还保留了在afArray中烘焙的添加/删除数组功能。很抱歉回复太晚,我一直很忙。我想我不清楚你所观察到的似乎不正确的是什么。在afworkitem模板中进行交换时,是否没有显示任何内容?在自定义afarrayfield模板中,即使将类型声明为select,字段是否仍显示为文本输入?