Search code examples
knockout.jscomputed-observable

Knockout computed not updating using observable array


I have the following ViewModel:

function vm(model) {

    var self = this;

    var Create = function (data) {
        var order = ko.utils.extend(data, {});
        order.Price = ko.observable(data.Price);
        return order;
    }

    self.orders = ko.mapping.fromJS(model, {
        create: function (options) {
            return Create(options.data);
        }
    });

    self.FirstPrice = ko.pureComputed(function () {
        return parseFloat(self.orders()[0].Price());
    });
}

When the page is loaded the "FirstPrice" is updated normally, but after change the Price on first row of "orders" array, the "FirstPrice" remains the first value after page load.

What is missing?

* I removed some lines of code to simplify the example

Thanks


Solution

  • I found the issue. The problem is that I'm using the inputmask in bound input.

    There is a workahound to this: https://github.com/RobinHerbots/jquery.inputmask/wiki/HOWTO:-Integration-with-Knockoutjs

    Sorry for not put the HTML where I used the observable in the question, this could help you to help me ;)

    Thanks again