2

I have two drop down boxes. I populate the second drop down box on the ko compute of the first drop down. I have two lists , one is populated with all the available values of the item selected in drop down. And to the right list, the user can select the values from the left lest which filled by the ko compute function, when ever a value is changed on the first or second drop down, I need to clear the seletedItems array (from the right side list), now the left list with the new values I try to select values to the right list, but the ko compute is called for every selection to the array seletedItems (which I cleared with removeAll in the ko compute), no idea why this is happening.Appriciate any help.

Thanks,

Mercy
  • 171
  • 3
  • 12
  • 8
    The relevant parts of your code would be helpful! – Niko Jun 08 '12 at 13:03
  • 2
    Can't really help without knowing what the code looks like. Please attach a fiddle link. – Paolo del Mundo Jun 08 '12 at 13:06
  • My ultimate aim is to watch a change on an array elements and depending on that I need to some action.I want to do this with out ko computing.I know there is a concept like subcribe in ko for obderving any value change of a variable instead of using ko compute. As being a beginner not able to get much info. If any one give sample of how to use a subscribe , that would be great help – Mercy Jun 11 '12 at 12:11
  • If you are looking for a `subscribe` example, the bottom of this page may help: http://knockoutjs.com/documentation/observables.html – Jason Capriotti Jun 12 '12 at 15:54

1 Answers1

0

Preface: I agree with Niko and Paolo del Mundo. We would be in a much better position to help you if you include code snippets.


With that being said, you indicated that your computed functions are unexpectedly calling themselves recursively.

  • If that is the case, then I recommend that you simplify your Knockout VM code.
  • Refactor, and favor manual subscriptions.

  • In spite of their expressiveness and power, computed functions can be tricky.
  • If you create too many of them, it can be difficult to predict when they'll be called.
  • With a sufficiently large dataset, IE 8 and older will flag overly complicated Knockout code with a slow running script warning.
Community
  • 1
  • 1
Jim G.
  • 15,141
  • 22
  • 103
  • 166