I am attempting to sort out an array by excluding users who are already on a previous list:
FullList: Tom, Tim, Jim, Jill
UsersList: Tom, Jill
With the help of a colleague, I managed to utilize this array filter. However, the issue is that the filtered result matches the UsersList: Tom, Jill and my desired outcome is Tim, Jim
var viewModel = function(data){
var _self = {};
var FullUsers = ko.observableArray([]);
var Users = ko.observableArray([]);
_self.UsersList = function(data){
$.each(data, function(index, user) {
_self.Users.push(new userViewModel(user));
}
}
_self.FullList = function(data){
$.each(data, function(index, user) {
_self.FullUsers.push(new userViewModel(user));
}
}
this._FilteredUsers=ko.computed(function() {
return ko.utils.arrayFilter(_self.FullUsers(), function(item) {
return ko.utils.arrayIndexOf(_self.Users(), item)<0;
});
});
}
I have two separate get methods - one for fetching users and the other for full users. They are essentially identical, except for the id I provide in one and not in the other.
View Data-bind
<div data-bind="foreach: _FilteredUsers">
<span data-bind="text: Name"></span>
</div>
How can I adjust the code to display Tim, Jim as the result?
Currently, based on the above code, I retrieve FullUsers including those I don't wish to display. When I switch the Users()
and FullUsers()
, I only obtain the Users list.