如何使用 RadioButtonList 并使用 Ember 获取所选值?
How to use a RadioButtonList and get the selected value with Ember?
我是 Ember 的新手,我正在做一个 asp.net 网络 api,它使用 Ember 调用,并且在我想要的表格上能够获得用户选择的值。我该怎么做?
我想与 Ember 一起使用的 RadioButtonLists 之一的示例:
<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>
像这样为 RadioButtonList 构建一个视图:
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 中使用它:
{{radio-button checked=model.nationalTransportation value=ntNotRequired}}
我是 Ember 的新手,我正在做一个 asp.net 网络 api,它使用 Ember 调用,并且在我想要的表格上能够获得用户选择的值。我该怎么做?
我想与 Ember 一起使用的 RadioButtonLists 之一的示例:
<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>
像这样为 RadioButtonList 构建一个视图:
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 中使用它:
{{radio-button checked=model.nationalTransportation value=ntNotRequired}}