Skip to content

Instantly share code, notes, and snippets.

@sshay77
Forked from maxcnunes/Debug-Knockout-JS.html
Last active May 22, 2024 11:07
Show Gist options
  • Save sshay77/a2e82fec919c790beca1bc5829248e20 to your computer and use it in GitHub Desktop.
Save sshay77/a2e82fec919c790beca1bc5829248e20 to your computer and use it in GitHub Desktop.
Simple way to debug viewmodel data bind with knockout
1.
<pre data-bind="text: ko.toJSON($data, null, 2)"></pre>
2.
<ul data-bind="debug: $data">
<a href="https://www.safaribooksonline.com/blog/2014/02/26/debugging-bindings-knockout-3-0/">1<a/>
<a href="https://github.com/JonKragh/knockthrough">2<a/>
3. <div data-bind="text: echo(value)"></div>
//2.
ko.bindingHandlers.debug =
{
init: function(element, valueAccessor)
{
console.log( 'Knockoutbinding:' );
console.log( element );
console.log( ko.toJS(valueAccessor()) );
}
};
//3
function echo(whatever) { debugger; return whatever; }
//Or
function echo2(whatever) { console.log(whatever); return whatever; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment