Q:

Knockout: Mapping with multiple keys

Is it possible to use the ko.mapping Plugin to check for multiple keys? Something like this...
var mapping = {
     key: function(data) {
         return ko.unwrap(data.id) && ko.unwrap(data.name)
     }
}

I want the Mapping Plugin to only add new items to the observableArray when the combination of id and name is not already used.

A:

I believe so.  Just concatenate them both into a string and return it.
var mapping = {
     key: function(data) {
         return ko.unwrap(data.id) + '_' + ko.unwrap(data.name);
     }
}

The underscore delimiter (or pipe or whatever you choose to use) should help with any key collisions like one object with id='12' name='times' and another with id='1' and name='2times'.

