0

Sometimes I get an error like this:

Uncaught Error: Unable to parse bindings.
Message: ReferenceError: items is not defined;
Bindings value: foreach: items() 

I'm pretty satisfied with my current way of debugging binding faults - see this answer.

Problem is that I sometimes don't know what element to debug. I use the propertyname items() everywhere in my project for different contexts.

Right now the only thing I can do to find the element is searching through my whole project for foreach: items() and replace it for debug: $data.

Is there some way to find the element after a throw?

Is there a way to let Knockout.js throw the element's xpath during a binding fault?

Community
  • 1
  • 1
Dirk Boer
  • 8,522
  • 13
  • 63
  • 111

1 Answers1

0

There isnt a great way to do this to my knowledge, but you can make javascript work for you a bit more by using named function declarations.

so replace this:

foreach: items()

with something like this:

foreach: function shoppingcartItems(){ return items(); }

or instead (if you want context detail) put them within your context:

var someKOContext = {

   items: function someKOContextItems(){ return realItems() }

}

var someOtherKOContext = {

  items: function someOtherContextItems() { return realItems() }

}

These tricks should enhance the readability of the console error messages somewhat, and give you a bit more information to track down where your error is occurring (or at least which context to start with, or html element)

techsaint
  • 752
  • 9
  • 22