-
-
Save beyond-code-github/96471c3e4d6feed349c1 to your computer and use it in GitHub Desktop.
Implementing addItem and removeItem in the change tracked array extender
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//.... | |
//.... | |
var findItem = function (array, item) { | |
return ko.utils.arrayFirst(array, function (o) { | |
return o === item; | |
}); | |
}; | |
var addItem = function (item) { | |
var previouslyRemoved = findItem(target.removed(), item); | |
if (previouslyRemoved) { | |
target.removed.remove(previouslyRemoved); | |
} else { | |
target.added.push(item); | |
target.isDirty(true); | |
} | |
}; | |
var removeItem = function (item) { | |
var previouslyAdded = findItem(target.added(), item); | |
if (previouslyAdded) { | |
target.added.remove(previouslyAdded); | |
} else { | |
target.removed.push(item); | |
target.isDirty(true); | |
} | |
}; | |
//.... | |
//.... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment