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?

1 Answer 1

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)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.