Using Chrome Console to Access Knockout ViewModel with RequireJS

后端 未结 3 1383
长情又很酷
长情又很酷 2021-01-31 05:07

How do I access the KnockOut ViewModel variables in the Chrome console now that I am using RequireJS?

Before using RequireJS, I followed a namespacing pattern, hiding ev

3条回答
  •  死守一世寂寞
    2021-01-31 05:26

    As Ryan suggested, the quickest way is to use ko.contextFor and ko.dataFor in the console to see the binding context of an element on the dom.

    There's also a very useful Chrome Extension that uses this principle called KnockoutJS Context Debugger, available here:

    Chrome Web Store - KnockoutJS Context Debugger

    It allows you to inspect an element and see it's context in the sidebar of the elements pane. It's most useful it you have multiple binding contexts on a page, or very nested binding contexts.

提交回复
热议问题