编程语言
首页 > 编程语言> > javascript – Meteor js:如何设置单选按钮?

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

作者:互联网

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

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

解决方法:

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

我一做到这一点:

<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>

生活很美好

标签:spacebars,javascript,meteor
来源: https://codeday.me/bug/20190728/1562538.html