Meteor js:如何设置单选按钮?

时间:2014-05-13 18:36:39

标签: javascript meteor spacebars

我有一组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}},就像在胡子中一样,可以阻挡已检查的属性。

渲染页面时设置当前值并不困难。

1 个答案:

答案 0 :(得分:7)

O.k。所以事实证明问题是无线电输入没有足够的名称。

我一做到这一点:

<div><input id="{{_id}}_undefined" type="radio" name="{{_id}}_accepted" {{undecided}}>No Determination</div>
<div><input id="{{_id}}_true" type="radio" name="{{_id}}_accepted" value="true" {{accepted}}>Assign To Researchers</div>
<div><input id="{{_id}}_false" type="radio" name="{{_id}}_accepted" value="false" {{declined}}>Decline</div>

生活很美好