0

My view displays a list composed objects all stored in koObservableArray MM.slideWellThumbnails

The objects are displayed using data-bind="foreach: slideWellThumbnails"

I couldn't get an individual view of an object updated, when only one property (e.g. confirmed ) of an object was changed.

  • I've tried to call: MM.slideWellThumbnails.valueHasMutated();
  • I've declared the array with: MM.slideWellThumbnails.extend({notify: 'always'});

It didn't help.

What I'm currently doing is, making a copy of the array, clearing the entire array and then pushing the data back to the array. It works, but I guess it is not as the KO-inventor ment it.

MM.slideWellThumbnails()[ +well ].confirmed = confirmed;
MM.slideWellThumbnails1([]);

ko.utils.arrayForEach( MM.slideWellThumbnails(), function(data)
{
    MM.slideWellThumbnails1.push( data );
});
MM.slideWellThumbnails([]);
ko.utils.arrayForEach( MM.slideWellThumbnails1(), function(data)
{
    MM.slideWellThumbnails.push( data );
});

Is there an efficient way to do it?

3
  • 2
    It looks like confirmed itself is just a simple property, not a ko.observable? The "correct" way to do it would be for it to be an observable that you can update the value of, without touching the array at all Commented Jun 23, 2015 at 13:05
  • 1
    I agree with @JamesThorpe. Any property that you want to react to changes on will need to be an observable. Commented Jun 23, 2015 at 13:17
  • @JamesThorpe Ok, thanks for pointing me to this! Could fix it. Commented Jun 23, 2015 at 13:44

1 Answer 1

1

Thanks to James Thorpe I could fix it:

Declared confirmed as observable:

var MyDataStructure= function( /*args*/ ) {
//...
this.confirmed = ko.observable(false)
//...
}

and assigned new value with:

//+well for explicitly converting to int from string
MM.slideWellThumbnails()[ +well ].confirmed(confirmed);

Thanks!

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.