我有一個函數,在裏面我正在做一些計算,我想把計算結果寫到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