0

I'm having an issue with KnockoutJs right now. I am a beginner, so for now I'm blaming my ignorance.

I have an observable array in a viewmodel. When any of the children are updated (which I verified through the console that they do in-fact change), I need the array to trigger a reflow/refresh of the view.

Here's why. My view creates an accordian based on the children, so grouping is involved. If a child changes it's group, it needs to move to a different place.

I did check out this SO How to force a view refresh without having it trigger automatically from an observable?

But observable.valueHasMutated() doesn't do anything. No errors, just nothing happens.

If anyone has a working example that I can learn from, or solution, that would be awesome.

I would post my code (and I may later if I can make it simple enough), but it's unfortunately not as easy as it sounds given the design of the app.

Community
  • 1
  • 1
Matt
  • 6,264
  • 10
  • 54
  • 82
  • You can call valueHasMutated on your observableArray or you can use an extender to subscribe to changes on the child observables – PW Kad May 28 '14 at 21:22

1 Answers1

1

From the documentation:

Key point: An observableArray tracks which objects are in the array, not the state of those objects

Simply putting an object into an observableArray doesn’t make all of that object’s properties themselves observable. Of course, you can make those properties observable if you wish, but that’s an independent choice. An observableArray just tracks which objects it holds, and notifies listeners when objects are added or removed.

So you need to make your "group" property observable and make sure your binding handler reads the observable within its update function.

Community
  • 1
  • 1
Michael Best
  • 16,623
  • 1
  • 37
  • 70
  • Well I managed to get it working after refactoring my code. Not sure exactly what fixed it but I'll give you points for your answer. – Matt Jun 19 '14 at 17:05