-
-
Save sshay77/a2e82fec919c790beca1bc5829248e20 to your computer and use it in GitHub Desktop.
Simple way to debug viewmodel data bind with knockout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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