Item Selection Mvc View With Knockoutjs
I am trying to implement a generic ASP.net MVC view. The UI should display a list of available and selected items loading data (basically list of string) from server. User can make
Solution 1:
As user3426870 mentioned, you need to change the value you passed to the checked binding to boolean.
<input type="checkbox" data-bind="checkedValue: $data, checked: isSelected" />
Also, I don't think you need to have selectedItems in the initial data.
Instead in the viewModel, you can do something like:
self.selectedItems = ko.computed(function() {
return ko.utils.arrayFilter(self.availableItems(), function(item) {
return item.isSelected();
});
});
Solution 2:
It's because you give an array to the binding checked
while it's supposed to be a value comparable to true
or false
(like undefind
or an empty string).
I would use a function checking if the $data
is in your array and returning a boolean to your binding.
Something like that!
Post a Comment for "Item Selection Mvc View With Knockoutjs"