I like KO framework, however debugging is sometimes just a nightmare for me. In case of regular javascript code I can put a breakpoint and go there at runtime and see what's wrong, but how to debug knockout expressions? In the most cases bindings errors are result of missing some symbol or wrong syntax, and sometimes knockout shows me clear errors regarding the issue, but sometimes not, expected data just not appeared on the page, or error messages like 'binding expression is wrong', even messages like 'function abc is not found' does not let me understand immediately what's wrong as I do not know which level of my model KO runtime is going through at the moment. Ideally there should be a browser plugin letting put breakpoints or something at any KO expression and see the context it running with at runtime. Is anything like this is on the market or expected? Any ideas regarding improving debugging process?
Asked
Active
Viewed 4,469 times
8
-
4A couple suggestions: Take a look here for a way to see your current context: http://stackoverflow.com/questions/9261296/any-good-techniques-to-debug-template-binding-faults-for-knockout-js. Also, if you really want to move your binding expressions out of the markup, then take a look at this project: https://github.com/rniemeyer/knockout-classBindingProvider – RP Niemeyer Sep 14 '12 at 01:53
-
Thanks. Same question has been answered – YMC Sep 14 '12 at 02:19
-
I make use of a small debug bindingHandler: http://stackoverflow.com/a/16242988/647845 – Dirk Boer Mar 16 '14 at 20:54
2 Answers
10
During development, I use the debug versions and set a breakpoint on the function createBindingsStringEvaluator()
(line 1858 in v2.1.0). So just before the bindings are "parsed," you can analyze the expression that would be evaluated, find out which bindings fail, their context and you could step through the binding process so you can walk through all the way until it fails.
To minimize problems for very complicated bindings, especially if they need to be repeated, I'd consider creating some custom binding handlers that can apply a set of bindings at once.

Jeff Mercado
- 129,526
- 32
- 251
- 272
-
-
2It depends on what sort of "failure" you have. If it happens in multiple bindings, deal with the problems one at a time. Understand why it failed by making sure everything is what you expect. – Jeff Mercado Jan 30 '13 at 04:23
0
In the current version (v 3.4.1), the function is called parseBindingsString. Setting a debugger
or a console.log
there, will get you some information.

K. Rohde
- 9,439
- 1
- 31
- 51