4

I'm developing a application with knockout.js framework. I have one viewmodel like that:

var MyViewModel= {
    Id: ko.observable(),
    CountryCode: ko.observable(),
    NormalizedAddress:
        {
            COUNTRY_CODE: ko.computed(function () { return this.CountryCode(); }),
            Street: ko.observable(),
            ZipCode: ko.observable(),
            AreaCode: ko.observable(),
            Town: ko.observable(),
            Description: ko.observable()
        }

When I run my application, I obtain one exception like that:

0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'CountryCode'

Can you help me to resolve my problem?

Thank you a lot, Marco

ilMattion
  • 1,841
  • 2
  • 24
  • 47
  • 1
    What is `this`? Have you checked? It probably isn't what you think it is... – elclanrs Mar 04 '16 at 15:52
  • check similar questions, you maybe didn't include some script properly http://stackoverflow.com/questions/27263635/0x800a01b6-microsoft-jscript-runtime-error-object-doesnt-support-property-or – Darko Rodic Mar 04 '16 at 15:53
  • I checked and this is the window object. There is a way for get the specific property? – ilMattion Mar 04 '16 at 16:24

1 Answers1

0

I resolved my problem using subscribing feature of knockout.

Now my code is like that:

var MyViewModel= {
    Id: ko.observable(),
    CountryCode: ko.observable(),
    NormalizedAddress:
        {
            COUNTRY_CODE: ko.observable(),
            Street: ko.observable(),
            ZipCode: ko.observable(),
            AreaCode: ko.observable(),
            Town: ko.observable(),
            Description: ko.observable()
        }
}

MyViewModel.CountryCode.subscribe(function (newValue) {
    MyViewModel.NormalizedAddress.COUNTRY_CODE(newValue);
});

So I can change the value when CountryCode property is changed.

Thanks

ilMattion
  • 1,841
  • 2
  • 24
  • 47