Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions angular-selectize.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
var optionsFn = $parse(optionsExpression);
var displayFn = $parse(match[2] || match[1]);
var valueFn = $parse(match[2] ? match[1] : valueName);
var objectKey = match[5];

watchParentOptions();

Expand Down Expand Up @@ -207,6 +208,15 @@
}
}

function arrayObjectIndexOf(arr, obj) {
for (var i = 0; i < arr.length; i++) {
if (angular.equals(arr[i], obj)) {
return i;
}
};
return -1;
}

function getSelectedItems(model) {
model = angular.isArray(model) ? model : [model] || [];

Expand All @@ -222,8 +232,14 @@

var selections = options.reduce(function(selected, option, index) {
var optionValue = getOptionValue(option);
if (model.indexOf(optionValue) >= 0) {
selected[optionValue] = index;
if (angular.isObject(optionValue)) {
if (arrayObjectIndexOf(model, optionValue) >= 0) {
selected[optionValue[objectKey]] = index;
}
} else {
if (model.indexOf(optionValue) >= 0) {
selected[optionValue] = index;
}
}
return selected;
}, {});
Expand Down