diff options
| author | Rory Douglas | 2013-05-27 10:59:19 -0700 | 
|---|---|---|
| committer | Igor Minar | 2013-07-24 14:16:26 -0700 | 
| commit | 47a2a9829f0a847bbee61cd142c43000d73ea98b (patch) | |
| tree | 2c653f37275e297099d70549567152f7d7c4d802 /src | |
| parent | a13c01a8e48ea4a0d59394eb94f1b12c50cfef61 (diff) | |
| download | angular.js-47a2a9829f0a847bbee61cd142c43000d73ea98b.tar.bz2 | |
fix(ngRepeat): handle iteration over identical obj values
Modifies default trackByIdFn to factor both key and value into hashKey
for non-array primitive (i.e. index not provided) values
Closes #2787
Closes #2806
Diffstat (limited to 'src')
| -rw-r--r-- | src/ng/directive/ngRepeat.js | 9 | 
1 files changed, 7 insertions, 2 deletions
| diff --git a/src/ng/directive/ngRepeat.js b/src/ng/directive/ngRepeat.js index fdf79c02..b5fa60dd 100644 --- a/src/ng/directive/ngRepeat.js +++ b/src/ng/directive/ngRepeat.js @@ -205,7 +205,7 @@ var ngRepeatDirective = ['$parse', '$animator', function($parse, $animator) {          var animate = $animator($scope, $attr);          var expression = $attr.ngRepeat;          var match = expression.match(/^\s*(.+)\s+in\s+(.*?)\s*(\s+track\s+by\s+(.+)\s*)?$/), -          trackByExp, trackByExpGetter, trackByIdFn, lhs, rhs, valueIdentifier, keyIdentifier, +          trackByExp, trackByExpGetter, trackByIdFn, trackByIdArrayFn, trackByIdObjFn, lhs, rhs, valueIdentifier, keyIdentifier,            hashFnLocals = {$id: hashKey};          if (!match) { @@ -227,9 +227,12 @@ var ngRepeatDirective = ['$parse', '$animator', function($parse, $animator) {              return trackByExpGetter($scope, hashFnLocals);            };          } else { -          trackByIdFn = function(key, value) { +          trackByIdArrayFn = function(key, value) {              return hashKey(value);            } +          trackByIdObjFn = function(key) { +            return key; +          }          }          match = lhs.match(/^(?:([\$\w]+)|\(([\$\w]+)\s*,\s*([\$\w]+)\))$/); @@ -266,7 +269,9 @@ var ngRepeatDirective = ['$parse', '$animator', function($parse, $animator) {            if (isArrayLike(collection)) {              collectionKeys = collection; +            trackByIdFn = trackByIdFn || trackByIdArrayFn;            } else { +            trackByIdFn = trackByIdFn || trackByIdObjFn;              // if object, extract keys, sort them and use to determine order of iteration over obj props              collectionKeys = [];              for (key in collection) { | 
