【发布时间】:2016-03-14 04:48:33
【问题描述】:
我有一个通过这个模板生成的下拉列表,位于ranvas.html:
<template name="shape-dropdown">
<select id = "shape-select">
<option value = "none">select a shape</option>
{{#each shape in shapes}}
<option value = "{{this}}"> {{this}} </option>
{{/each}}
</select>
</template>
它从ranvas.js 中的帮助器获取形状名称:
Template.shape-dropdown.helpers({
shapes: [
{ shapetype: "random line"},
{ shapetype: "random quadratic curve"},
{ shapetype: "random bezier curve"},
{ shapetype: "random arc"},
{ shapetype: "random stroke triangle"},
{ shapetype: "random fill triangle"},
{ shapetype: "random stroke rectangle"},
{ shapetype: "random fill rectangle"}
{ shapetype: "random stroke circle"},
{ shapetype: "random fill circle"},
]
});
选择其中一种形状时,我希望一个位于 shape-templates.html中的模板加载。
For example when the "random line" option is selected, I want this template to load:
<template name="rand_line">
<label>x1: <input type="text"> - <input type="text"></label>
<label>y1: <input type="text"> - <input type="text"></label>
<label>x2: <input type="text"> - <input type="text"></label>
<label>y2: <input type="text"> - <input type="text"></label>
{{> rand_strokeStyle}}
</template>
【问题讨论】:
-
您可以将 Dynamic 模板助手与从下拉列表的
change事件处理程序设置的反应变量一起使用。 -
你在使用 Iron Router 吗?
-
@StefanL19 不,我不是
-
你尝试过使用 Sessions 吗?
标签: javascript templates meteor