3
votes

I have an observableArray of objects in my view model, and within, I have an observable property on one key:

var somefunc = function(sysMsgs)
{
    // Create a VO from passed array
    $.each(sysMsgs, function(i, v) {
    var tMsg = {
        ...
        READ : ko.observable(v.READ),
        ...
    };
    systemMessagesArray.push(tMsg); // Already Initialized observableArray
   });
}

I need to subscribe to changes on the READ key so that I can disable form controls in the view. On a regular observable, I would:

variable.subscribe(function(v) {do something with the value v;});

Any idea on how to scribe to the key within the array? Thanks...

1

1 Answers

0
votes

Have you tried that ?

var somefunc = function (sysMsgs) {
    // Create a VO from passed array
    $.each(sysMsgs, function (i, v) {
        var tMsg = {
            READ: ko.observable(v.READ),
        };
        systemMessagesArray.push(tMsg);
        tMsg.subscribe(function {
            alert('changed');
        });
    });
};