Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access denied from ko.toJSON

my view model is very simple

var viewModel = {

    self: this,

    description: ko.observable('some description'),
    dateOfLost:  ko.observable('01/01/2012'),
    plaintiffFirmName: ko.observable('Johnson, Brand & Tall'),
    claimantName: ko.observable(),
    claimNum: ko.observable(),

    getFormData:function () {

        alert('event');

        GetClaimData();

    }
};

but when I'm trying to access model from html page

<pre data-bind="text: ko.toJS($data)"></pre>

I'm getting error - Access denied. Can any one tell me why? please note that all the fields above that line binded properly

Many thanks

like image 324
Yuri Avatar asked Oct 20 '22 22:10

Yuri


1 Answers

Remove self:this from viewModel

var viewModel = {
    description: ko.observable('some description'),
    dateOfLost:  ko.observable('01/01/2012'),  

in current context this is window object. The same error you will get by calling ko.toJS(window)

JSFiddle DEMO

like image 112
Ilya Avatar answered Oct 23 '22 23:10

Ilya