【发布时间】:2015-02-26 19:41:10
【问题描述】:
如何将存储的 true 或 false 值应用于选中的属性?
我有一系列问题,用户可以在其中打开/关闭(真/假)作为答案。我在 Meteor.user().profile 中创建了一个名为 questions 的对象。字段名称是问题,存储的值是true 或false。
现在我希望每个字段的属性显示存储的值,而不是重置为其默认值。
<template name="template">
{{#with currentUser.profile.questions}}
<div class="row">
<input data-name="profile.questions.school" type="checkbox" name="questions" checked="{{school}}"> Go to School?
</div>
<div class="row">
<input data-name="profile.questions.contributor" type="checkbox" name="questions" checked={{contributor}}"> contributor?
</div>
{{/with}}
</template>
我这样做是不是很啰嗦?无论如何使用空格键{{isChecked}} 方法会有所帮助吗? https://www.discovermeteor.com/blog/spacebars-secrets-exploring-meteor-new-templating-engine/
似乎只是为了显示复选框。
【问题讨论】:
-
空格键中没有
isChecked这样的东西。但是,使用<input type="checkbox" checked="{{value}}">,其中value是true或false,应该可以工作。见github.com/meteor/meteor/wiki/…