我有一组 3 个单选按钮,我试图在首次呈现页面时设置它们:
<div>
<div><input id="{{_id}}_undefined" type="radio" name="accepted" {{undecided}}>No Determination</div>
<div><input id="{{_id}}_true" type="radio" name="accepted" value="true" {{accepted}}>Assign To Researchers</div>
<div><input id="{{_id}}_false" type="radio" name="accepted" value="false" {{declined}}>Decline</div>
{{#if declined}}
<textarea name="declineReason" ></textarea>
{{/if}}
<button id="saveChanges" data-research-request-id="{{_id}}">Save Changes</button>
</div>
使用这些助手:
Template.su_researchRequests.helpers({
// This feels so wrong.
accepted: function() {
return this.accepted === true?'checked':'';
},
declined: function() {
return this.accepted === false?'checked':'';
},
undecided: function() {
return this.accepted !== false && this.accepted !==true?'checked':'';
}
});
我尝试使用 {'checked':''} 或 {} 返回一个对象
我不能像在胡须中那样在流星中使用 {{#if}} 来阻止选中的属性。
渲染页面时设置当前值并不难。