BonyT
BonyT

Reputation: 10940

Knockout - multi-select lists on a dependentObservable (or computed)

I have a fiddle for this issue which has been annoying me for a few days now: fiddle

The pattern of including a selectedUserReport observable as well as a SelectedRecord dependentObservable is one I took from here

The problem I have is that the PageModel.SelectedRecord function is evaluating whenever you click an item in the multi-select list, which prevents you from selecting any items.

Can anyone point me in the right direction?

Upvotes: 1

Views: 517

Answers (1)

Kyeotic
Kyeotic

Reputation: 19847

You had a syntax error, here is the working fiddle

selectedOptions: SelectedColumns //Shortcut, if prop is in context (it isn't right now)
selectedOptions: $parent.SelectedColumns //illegal
selectedOptions: $parent.SelectedColumns() //Correct

The issue is that when referencing an observable by itself, knockout allows you to drop the parens. However, anything else like an inline function or other reference, you need to the use parens. You were using the illegal line in the middle.

Edit:
Ok, so the saving is a bit of a mess to get into, but basically your save code was pushing data incorrectly. Here is another fiddle. Note, the edit line is now:

self.selectedUserReport(new userReportModel(data));

You weren't constructing a new model, you were just pushing the data. This has broken the dialog closing now, but the if you close it manually it will reopen the the selected options properly selecting. I hope you can manage it from here.

Upvotes: 1

Related Questions