Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 0073aac

Browse files
committed
WIP: fix object / multiple viewValue computation
1 parent 3d35d16 commit 0073aac

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/ng/directive/select.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -399,16 +399,22 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
399399
optionGroup = optionGroupsCache[groupIndex];
400400

401401
for(index = 1, length = optionGroup.length; index < length; index++) {
402-
//Have to use attr because element[0].selected returns false when multiple selected
403-
if ((optionElement = optionGroup[index].element).attr('selected')) {
402+
if ((optionElement = optionGroup[index].element)[0].selected) {
404403
key = optionElement.val();
405404
if (keyName) locals[keyName] = key;
406405
if (selectAsFn) {
407406
var collectionWithValueName = {};
408407
collectionWithValueName[valueName] = collection[key];
409-
for (i = 0; i < collection.length; i++) {
410-
locals[valueName] = collection[i];
411-
if (selectAsFn(scope, locals) == selectAsFn(scope, collectionWithValueName)) break;
408+
collectionWithValueName[keyName] = key;
409+
410+
for (i in collection) {
411+
if (collection.hasOwnProperty(i)) {
412+
locals[valueName] = collection[i];
413+
locals[keyName] = i;
414+
if (selectAsFn(scope, locals) ==
415+
selectAsFn(scope, collectionWithValueName)) break;
416+
}
417+
412418
}
413419
} else if (trackFn) {
414420
for (trackIndex = 0; trackIndex < collection.length; trackIndex++) {
@@ -418,7 +424,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
418424
} else {
419425
locals[valueName] = collection[key];
420426
}
421-
value.push(valueFn(scope, locals));
427+
value.push((selectAsFn || valueFn)(scope, locals));
422428
}
423429
}
424430
}

test/ng/directive/selectSpec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ describe('select', function() {
591591
});
592592

593593

594-
iit('should bind to scope value through selectAs expression while tracking object via track by', function() {
594+
it('should bind to scope value through selectAs expression while tracking object via track by', function() {
595595
createSelect({
596596
'ng-model': 'selected',
597597
'ng-options': 'item.id as item.name for item in values track by item.id'

0 commit comments

Comments
 (0)