【发布时间】:2016-11-17 10:21:36
【问题描述】:
我正在尝试创建一个模板,以便在开头有一个通过 mongo 填充的下拉列表。我有第二个模板,它显示一个表格,其中包含基于上述选择的更多详细信息。为了显示表格中的内容,我必须首先能够检索从下拉列表中选择的值。我该怎么做?
我尝试使用this.schemaName 和defaultTemplate.schemaName 检索它,但没有帮助。
模板:
<template name ='defaultTemplate'>
<div class="form-group" data-required="true">
<label for="Schema" class="control-label">Select the Schema</label>
<select required="true" class="form-control">
<!-- <option default>Select Schema </option> -->
{{ #each schemaNames}}
<option >{{schemaName}}</option>
{{/each}}
</select>
<span class="help-block"></span>
</div>
{{> tableTemplate}}
</template>
<template name="tableTemplate">
<table class="table table-bordered table-condensed">
<thead>
<tr>
<td style="width: 85px">Label</td>
<td>Current Value</td>
<td style="width: 250px">New Value</td>
</tr>
</thead>
<tbody>
{{#each schemaLabels}}
<tr>
<td>{{this.label}}</td>
<td>{{this.value}}</td>
<td>
{{#autoForm id=makeUniqueID type="update" collection=Defaults doc=this autosave=true}}
{{> afFormGroup name="value" label=false}}
{{/autoForm}}
</td>
</tr>
{{/each}}
</tbody>
</table>
</template>
助手:
import { Template } from 'meteor/templating';
import '../templates/defaultTemplate.html';
Template.defaultTemplate.helpers({
schemaNames: function () {
return Defaults.find({},{schemaName:1}).map(function(c) {return {schemaName : c.schemaName};
});
},
schemaLabels: function() {
var selectedSchema = defaultTemplate.schemaName;
// alert (selectedSchema); >>>>>>>>>> Displays Undefined <<<<<<<<<<<
return Defaults.find({schemaNeme:selectedSchema},{schemaName:0,_id:0}).map(function(c) {return {label : c.label, value: c.value};
});
}
});
【问题讨论】:
标签: javascript mongodb meteor meteor-blaze meteor-helper