我对 Ember 相当陌生(使用版本 0.2.3)。我有一个带有一些计算值的组件。他们从输入字段收集这些计算值:
export default Component.extend({
loanAmount : 200000,
deductible : 0,
debtInt : 5,
getLoanCosts: computed('loanAmount', 'debtInt', function(){
return (get(this, 'debtInt')/12) * get(this, 'loanAmount');
})
在我的 template.hbs 上,我有一个输入字段{{ input value=loanAmount }}
我可以打电话{{getLoanCosts}}
在我的 template.hbs 中,显示计算的成本。这对于文本/数字输入非常有用。
但是,我需要一个带有两个值(是和否)的单选按钮输入。这应该与deductible
我的组件的价值(即这笔贷款可以扣除吗?)。但是,如果我这样做:
Yes {{ input type="radio" name="deductible" value=deductible }}
No {{ input type="radio" name="deductible" value=deductible }}
我无法像使用直接 HTML 那样为这两个输入设置值。如果我设置 value=0 和 value=1,它们永远不会在我的组件中更新。我怎样才能更新我的deductible
在组件中基于是否选择“是”或“否”?
是的,Ember 没有内置对单选按钮的支持。尝试制作自己的组件!我所说的“自制”是指无耻地从别人那里偷一个internet https://github.com/Blooie/ember-radio-buttons.
import Ember from 'ember';
export default Ember.Component.extend({
tagName: 'input',
type: 'radio',
attributeBindings: ['type', 'htmlChecked:checked', 'value', 'name', 'disabled'],
htmlChecked: function() {
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')
});
在组件中,单选按钮仍然具有值,但选择的绑定是传入的选中属性:
Yes{{radio-button value='1' checked=choice}}
No{{radio-button value='0' checked=choice}}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)