gpt4 book ai didi

javascript - ValueBinding 无法在我的 Ember View 中添加新对象

转载 作者:行者123 更新时间:2023-12-03 11:35:12 25 4
gpt4 key购买 nike

我有一个输入字段类型数字,其中显示两个值相乘的结果。

我已经设置了总函数,这是我在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 和 valueBinding=newThread.total 以获得总结果

    <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如您所见,最后一列中的结果值未绑定(bind)

最佳答案

分配给 newThread 属性的对象的 total 属性永远不会随结果一起设置。因此,一种方法可能是使总属性成为计算属性并在那里进行乘法。然后在 View 中显示该属性。

http://emberjs.jsbin.com/vivohiyefu/1/edit?html,js

关于javascript - ValueBinding 无法在我的 Ember View 中添加新对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26548725/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com