Uncaught TypeError: Property 'ha' of object [object Object] is not a function

451 views
Skip to first unread message

robert shoults

unread,
Jan 2, 2013, 4:08:19 PM1/2/13
to knock...@googlegroups.com
I have a parent object VM.  It holds a child object that also have observable properties.

The child object has the following properties
  • private observable array that serves as the datasource for a select HTML element on the UI.
  • public computed that controls read write access to the private observable array.

  • private observable selectedValue property that serves as the datasource for the value attribute of the select HTML element.
  • public computed selectedValue property that controls access to the private observable selectedValue.

Flow:
  • xhr gets list from server
  • download function creates an array and sets the private observable array to the new array via its public computed property's write function.
  • This same write function also sets the selectedValue private observable property via its public computed property.

Ultimately, what I get is a populated select HTML element and a value set as a default selection.  By using the public computed interface to the private observables, I get an input validation hook. 

This all works great.  However, i have a need to provide an update to the parent VM whenever the selected value changes.   I am a newbie to KO and, at first, I did not know about the subscribe method.  Therefore, I implemented my own observer pattern that called back to the parent VM from within the write function of the public computed selectedValue property.    This worked great.

Later I learned about the subscribe function offered by KO.  So I disabled my observer pattern and subscribed the parent VM to the selectedValue public computed property on the child VM object.   When I test the design, I get an error from KO.  Uncaught TypeError: Property 'ha' of object [object Object] is not a function.  I tracked this and this occurs when the write function of the public computed selectedValue property attempts to update the private observable selectedValue property it protects.

Any throughs?  

There is no ha property anywhere in my code so this must be something set by KO internally.
Message has been deleted

austin...@gmail.com

unread,
Jun 17, 2013, 12:11:19 AM6/17/13
to knock...@googlegroups.com
Try declaring your Knockout select input using the "optionsValue" parameter instead of the "optionsText" parameter.

Typically you’d only want to use optionsValue as a way of ensuring that KO can correctly retain selection when you update the set of available options. For example, if you’re repeatedly getting a list of “car” objects via Ajax calls and want to ensure that the selected car is preserved, you might need to set optionsValue to "carId" or whatever unique identifier each “car” object has, otherwise KO won’t necessarily know which of the previous “car” objects corresponds to which of the new ones.

Reply all
Reply to author
Forward
0 new messages