首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用RadioButtonList并使用Ember获取选定的值?

如何使用RadioButtonList并使用Ember获取选定的值?
EN

Stack Overflow用户
提问于 2015-02-20 11:34:44
回答 1查看 26关注 0票数 0

我是Ember的新手,我正在做一个名为“使用Ember”的asp.net web,在我正在制作的表单上,我希望能够得到用户选择的值。我该怎么做?

我想与Ember一起使用的一个RadioButtonLists示例:

代码语言:javascript
复制
   <div class="form-group">
       <label for="nationalTransportation">3.1. NATIONAL TRANSPORTATION (*)</label>
       <div class="radio">
            <label><input type="radio" name="National Transportation" value="Not Required">Not Required</label>
       </div>
       <div class="radio">
            <label><input type="radio" name="National Transportation" value="Public Transportation">Public Transportation</label>
       </div>
       <div class="radio">
            <label><input type="radio" name="National Transportation" value="Own vehicle">Own vehicle (subject to approval)</label>
       </div>
       <div class="radio">
             <label><input type="radio" name="National Transportation" value="Car Rental">Car Rental (subject to approval)</label>
       </div>
   </div>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-03-11 09:36:21

为RadioButtonList构建视图,如下所示:

代码语言:javascript
复制
App.EventRadioView = Ember.View.extend({

    tagName: 'input',
    type: 'radio',
    attributeBindings: ['type', 'htmlChecked:checked', 'value', 'name'],

    htmlChecked: function () {

        if (this.get('value') === 'Required' && this.get('name') === 'accommodation') {
            $('#panelAccommodation').css("display", "none");
        } else if (this.get('value') === 'Not Required' && this.get('name') === 'accommodation') {
            $('#panelAccommodation').css("display", "block");
        } else if (this.get('value') === 'Required' && this.get('name') === 'flight') {
            $('#panelFlight').css("display", "none");
        } else if (this.get('value') === 'Not Required' && this.get('name') === 'flight') {
            $('#panelFlight').css("display", "block");
        }
        return this.get('value') === this.get('checked');
    }.property('value', 'checked'),

    change: function () {
        this.set('checked', this.get('value'));
    },

    _updateElementValue: function () {
        Ember.run.next(this, function () {



            this.$().prop('checked', this.get('htmlChecked'));
        });
    }.observes('htmlChecked')
});

然后在html中使用它:

代码语言:javascript
复制
{{radio-button checked=model.nationalTransportation value=ntNotRequired}}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28628012

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档