diff --git a/src/angular-multi-select.js b/src/angular-multi-select.js index 9149715..b800b49 100644 --- a/src/angular-multi-select.js +++ b/src/angular-multi-select.js @@ -319,10 +319,9 @@ angular_multi_select.directive('angularMultiSelect', (function () { var dupes = {}; + var fnd = (function(d, o, n) { return fn(o, n, d); }).bind(this, dupes); for(_idx in obj[key]) { - var new_obj = $scope._walk(obj[key][_idx], key, (function(d, o, n) { - return fn(o, n, d); - }).bind(this, dupes)); + var new_obj = $scope._walk(obj[key][_idx], key, fnd); if (new_obj !== null) { sub.push(new_obj); } @@ -356,8 +355,9 @@ angular_multi_select.directive('angularMultiSelect', }); $scope._walk(dst, attrs.groupProperty, function (o, e) { var label = $scope._interpolatedItemLabel(o); - var prop = o[attrs.tickProperty]; - o[attrs.tickProperty] = tree[e][label]; + if (tree[e] && o[attrs.tickProperty] !== tree[e][label]) { + o[attrs.tickProperty] = tree[e][label]; + } return true; }); }; @@ -783,8 +783,8 @@ angular_multi_select.directive('angularMultiSelect', if (typeof dupes === "undefined") return true; var label = $scope._interpolatedItemLabel(obj); if (dupes[label]) return false; - else return (dupes[label] = true) - } + else return (dupes[label] = true); + }; /** * Returns true if [attrs.searchProperty} matches the search input field (latinized, fuzzy match);