私は Knockout.js が初めてで、UI に 3 つのフィールドがあります。商品価値。数量合計
計算されたオブザーバブルですべてが正常に機能し、データを保存できます。ビジネス上の理由により、合計はバックエンドで変更されます。
データを取得している間、DB からの合計を初期値として表示する必要がありますが、ユーザーが製品と値を変更した場合は、元の計算関数を使用する必要があります。
bindingHandlers を試しましたが、うまくいきませんでした..
ヘルプは非常に高く評価されます。
var TsFoundationDeviceModel = function(product,qty,total) {
var self = this;
self.product = ko.observable(product);
self.quantity= ko.observable(qty);
self.computedExample = ko.computed(function() {
return self.product() * self.quantity() ;
});
}
<input name="product" data-bind="value:product">
<input name="value" data-bind="value:value">
<input name="total" data-bind="value:computedExample"/>