我有可讀寫的總計算輸入框。計算寫入不適用於陣列
<div data-bind="foreach:TotalCostQuantity">
<input data-bind:"value: Cost, valueUpdate:'afterkeydown'" /><br />
<input data-bind:"value: Quantity, valueUpdate:'afterkeydown'" />
</div>
我的視圖模型是這樣的:
self.TrancheCostQuantity = ko.computed({
read: function() {
//do some math here to calculate cost and quant totals
return [{Cost:100, Quantity:10},{Cost:200, Quantity:20}];
},
write: function (newValue) {
customformat(newValue);
}
}, self);
的成本和數量都從能有行和列的動態數量的網格。它使用ko.mapping插件進行映射。
我需要寫入,但它從來沒有。閱讀工作正常,但我無法驗證或自定義格式我的寫道。
你能不能做一個小提琴? – Damien
'customformat'函數的作用是什麼? –
customformat將使TrancheCostQuantity向上舍入到最近的美元並添加一個美元符號。 – user1175857