0

I have two knockout models. On a change event in one model I want to access the property of the second model and modify it. I am not able to get the value from the second model.

First Model

var firstModelVM = function (data, root) {
            ko.observableListItem.call(this, data);
            var self = this;
            this.id = ko.observable();
            this.isPercentAvailable = ko.observable();
            this.name = ko.observable();

            enableCentralImp: function (data, event) {
                var select = $(event.target).is(':checked');
                this.elementID
            }

Second Model

 var secondModelVM = function (data, root) {
                ko.observableListItem.call(this, data);
                var self = this;
                this.defaultValue = null;
                this.defaultPercentage = null;
                this.isMoney = null;
                this.elementID = null;
                this.overrideValue = ko.observable();
                this.overridePercentage = ko.observable();
                this.comments = ko.observable();
            }

I am trying to access the elementID property of secondModelVM inside the firstModelVM so I can modify it. Can some one please tell me how to do this.

Thanks

ZeldaLink
  • 1
  • 2
  • 3
    Possible duplicate of [Whats the best way of linking/synchronising view models in Knockout?](https://stackoverflow.com/questions/9892124/whats-the-best-way-of-linking-synchronising-view-models-in-knockout) – Jason Spake Nov 14 '18 at 21:05
  • Also see: http://www.wrapcode.com/communication-between-multiple-view-models-in-knockoutjs-mvvm-the-right-approach/ – Jason Spake Nov 14 '18 at 21:06
  • What is the relation between firstModelVM and secondModelVm ? – Amit Bhoyar Nov 14 '18 at 21:55
  • firstModelVM 1: Many with secondModelVm, When values in firstModelVM changes on checkbox change event the secondModelVm properties should change specially the int number of elementID property i want to modify onchange of firstModelVM . – ZeldaLink Nov 15 '18 at 02:55

0 Answers0