Knockout UNable to Bind $root

孤人 提交于 2019-12-24 14:05:23

问题


Inside my Document i've added <div data-bind="text: ko.toJSON($root)"></div> to my html5 page. Unfortunately IE8 gives me an Error 'Unable to apply binding to $root' or similar.

No Problems on FF and Chrome.

How can i retuen a json dump of my current viewmodel for debugging needs?


回答1:


I was able to repro your issue: the problem isn't with your binding but with the ko.toJSON call. Knockout uses the JSON.stringify function internally which fails in your case.

Altough Is JSON.stringify() supported by IE 8? where the answer is yes.

But sometimes it is just not working: JSON object undefined in Internet Explorer 8 because IE is too picky and if you have errors in your html markup it will fall back to compatibility mode where there is no JSON.stringify definied.

You have two options:

  • Check your HTML to make IE8 happy and don't render it in compatibility mode
  • Use JSON2 library which provides JSON.stringify in older browsers.


来源:https://stackoverflow.com/questions/14382467/knockout-unable-to-bind-root

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!