knockout.viewmodel icon indicating copy to clipboard operation
knockout.viewmodel copied to clipboard

toModel excluding computed observables

Open ielcoro opened this issue 11 years ago • 2 comments

When using a viewModel with computed observables, updatingFromModel works fine, but when mapping back to the model, using toModel, ko.viewmodel omits all computed observables.

When using ko is usual that some extenders replace the current observable with a computed one, so in that case ko.viewmodel becomes unusable.

It appears to be a explicit filter on the recrusiveTo function, excluding all the computed observables:

   if (!ko.isComputed(child) && !((temp = unwrap(child)) && temp.constructor ===       Function)) {

                        recursiveResult = recrusiveTo(child, {
                            name: p,
                            parent: (context.name === "[i]" ? context.parent : context.name) + "." + p,
                            full: context.full + "." + p
                        });

                        //if badResult wasn't returned then add property
                        if (recursiveResult !== badResult) {
                            result[p] = recursiveResult;
                        }
                    }

I did eliminated that filter and now is working as expected.

 if (!((temp = unwrap(child)) && temp.constructor === Function)) {

Can I submit the change?

ielcoro avatar Mar 20 '14 16:03 ielcoro

Agreed! Must apply patch

olavorn avatar Nov 26 '15 06:11 olavorn

Is this applied? This plugin is unusable if not. Nuget seems to still have old version.

cblaze22 avatar Feb 03 '16 02:02 cblaze22