【发布时间】:2016-06-28 23:58:53
【问题描述】:
我有一个应用程序,它可能有数百种不同的表单(由用户创建)。
为了解决这个问题,我的计划是收集表单,其中每个文档都包含以下内容:
{
formTitle: "form title goes here",
version: 1.0,
fieldsets: [
{
fieldsetTitle: "Personal information",
introMessage: "Please provide your name and date of birth",
inputs: [
{
label: "Full name",
type: "text",
placeholder: "John Doe"
},
{
label: "Date of birth",
type: "date",
placeholder: "DD/MM/YYYY"
}
]
}
]
目前我的 blaze 模板包含一个 formName var,如下所示:
{{> form formName="form title goes here" }}
Template.form.onCreated(function(){
var thisFormName = this.data.formName; // this returns fine
var thisForm = Forms.findOne({formName: thisFormName}); //also works fine
console.log(thisForm); // prints the form document to console
})
但是,我不能在我的模板中访问这些数据。
<template name="form">
{{thisForm.formTitle}} // doesn't print the title and as such I cannot use the document within the template.
</template>
由于这是一个模块的模板,我无法通过路由获取数据(据我所知)。
有人知道我缺少什么吗?
我确定这是由于在从集合返回文档之前模板呈现,但是我不确定如何解决这个问题(因为我不能使用路由等待功能,例如 waitOn)
提前致谢。
【问题讨论】:
标签: meteor collections meteor-blaze