【发布时间】:2014-10-24 13:20:12
【问题描述】:
我有一个输入字段类型编号,其中显示两个值相乘的结果。
我已经在 html 中设置了我的 valueBinding 的总函数
这是我的 Ember.View.extend 与总计算
App.TotalView = Ember.View.extend({
templateName: 'total',
tagName: 'input',
attributeBindings: ['total:value', 'placeholder', 'type'],
placeholder: null,
type: 'number',
total: (function() {
var res= parseInt(this.get('controller.newThread.selectContentTariffa')) * parseInt(this.get('controller.newThread.primary'));
return isNaN(res)?"":res;
}).property('controller.newThread.selectContentTariffa', 'controller.newThread.primary')
});
我已经定义了对我的 NewThread 的调用
newThread:function(){
return {selectContentTariffa:null,primary:null,total:null,weight:null};
}.property(),
这是我选择计算值时的 html:valueBinding=newThread.selectContentTariffa, valueBinding=newThread.primary and valueBinding=newThread.total for the total result
<tr>
<td>{{view Ember.Select
prompt="Tariffa"
valueBinding=newThread.selectContentTariffa
content=selectContentTariffa
optionValuePath="content.value"
optionLabelPath="content.label"}}
</td>
<td>{{view Em.TextField
type="number"
valueBinding=newThread.primary
class="form-control"}}
</td>
<td>{{view "total" valueBinding=newThread.total}}</td>
<td><button class="btn btn-success" {{action add item}}>Add</button></td>
</tr>
<script type="text/x-handlebars" data-template-name="total">
{{view.total valueBinding=newThread.total}}
</script>
这是我添加后显示的值的我的 html
{{#each item in model}}
<tr>
<td>{{item.selectContentTariffa}}</td>
<td>{{item.primary}}</td>
<td>{{item.total}}</td>
</tr>
{{/each}}
我不知道我错过了什么,我在这里重现了这个问题:http://emberjs.jsbin.com/qakado/13/edit?html 你可以在未绑定下的最后一列中看到结果的值
【问题讨论】:
标签: javascript model-view-controller ember.js jsfiddle jsbin