Knockout Computed field never updates UI

18 Views Asked by At

I have some computed fields that I setup as get the model from JSon.

The event is triggered on the related fields change and the calculation is correct but the value is never presented on the UI.

There are some related posts that relates this problem with the previous fill off the model with data. I cannot overcome this, because the model come from the server and I need the values on the model to return to the server.

MODEL CREATION


self.GetModel = function () {
    MyShell().Dialog.showWaitingBox();

    var endpoint = GetUrlBase() + 'api/SDUtils/GetModelFechoCaixa';

    $.ajax({
        type: "GET",
        contentType: "application/json; charset=utf-8",
        url: endpoint,
        async: false,
        success: function (data) {


            if (self.Entity == null) {
                self.Entity = ko.mapping.fromJS(data);
            } else {
                ko.mapping.fromJS(data, self.Entity);
            }

            MyShell().Dialog.closeWaitingBox();
            ApplyEtiComponents();
        },
        error: function (d) {
            MyShell().Dialog.closeWaitingBox();
            MyShell().Dialog.showMessageBox(0, 0, "error", getMsgTranslated("generic", "ERP Eticadata"),"Erro a obter Modelo", getMsgTranslated("generic", "OK"));
        }
    });
}

COMPUTED FIELDS


self.AutoUpdate = function () {

    self.Entity.Diferencas.MB = ko.computed(function () {
        var Diff = self.Entity.Camping.MB() + self.Entity.eSport.MB() - self.Entity.Caixa.MB();
        console.log("MB:", self.Entity.Caixa.MB(), "DIF", Diff);
        return Diff;
    },self);
    ApplyEtiComponents();
}
0

There are 0 best solutions below