我有一个函数,在里面我正在做一些计算,我想把计算结果写到observable。无法写入可观察?使用里面写的计算
视图模型:
function data()
{
var innerself=this;
innerself.Amount=ko.observable("");
innerself.Volume = ko.observable("");
innerself.Rate=ko.observable("");
innerself.AutoCalculate = ko.computed({
read: function() {
var qty = innerself.Volume();
var val = qty * innerself.Rate();
// innerself.Amount(val.toFixed(2)); its wrong to use like this i feel
return val;
},
write: function (value) {
innerself.Amount(value); // kept break point but its not getting hit at all but read function excecutes
}
},innerself);
}
查看:
//running loop on top via foreach:observablearray
<input type="text" data-bind="value:$data.Volume " />
<input type="text" data-bind="value:$data.Rate"/>
<input type="text" data-bind="value:$data.Amount"/>
我使用嵌入功能一切,所以后来我创建了一个对象,并推到observablearray对象等并且我将循环通过该可观察阵列。
任何建议表示赞赏。
什么问题?你在某处遇到错误吗? – PatrickSteele 2014-11-05 12:38:24
没有错误队友一切都很好,但金额是remians空白becoz写甚至没有射击我相信 – 2014-11-05 13:33:56