Skip to content

Commit ffc1fcb

Browse files
Nedyalko NikolovErjanGavalji
Nedyalko Nikolov
authored andcommitted
Fixed issue with updating nested properties via binding.
1 parent 0dc6156 commit ffc1fcb

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

apps/tests/ui/bindable-tests.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,4 +541,36 @@ export function test_BindingToDictionaryAtAppLevel() {
541541
}
542542

543543
helper.buildUIAndRunTest(createLabel(), testFunc);
544+
}
545+
546+
export function test_UpdatingNestedPropertyViaBinding() {
547+
var expectedValue1 = "Alabala";
548+
var expectedValue2 = "Tralala";
549+
var viewModel = new observable.Observable();
550+
var parentViewModel = new observable.Observable();
551+
viewModel.set("parentView", parentViewModel);
552+
parentViewModel.set("name", expectedValue1);
553+
554+
var testElement: bindable.Bindable = new bindable.Bindable();
555+
556+
testElement.bind({
557+
sourceProperty: "parentView.name",
558+
targetProperty: "targetName",
559+
twoWay: true
560+
}, viewModel);
561+
562+
var testElement2: bindable.Bindable = new bindable.Bindable();
563+
564+
testElement2.bind({
565+
sourceProperty: "parentView.name",
566+
targetProperty: "targetProperty",
567+
twoWay: true
568+
}, viewModel);
569+
570+
TKUnit.assertEqual(testElement.get("targetName"), expectedValue1);
571+
572+
testElement.set("targetName", expectedValue2);
573+
574+
TKUnit.assertEqual(parentViewModel.get("name"), expectedValue2);
575+
TKUnit.assertEqual(testElement2.get("targetProperty"), expectedValue2);
544576
}

ui/core/bindable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ export class Binding {
261261
else {
262262
this.updateTarget(expressionValue);
263263
}
264-
} else if (data.propertyName === this.options.sourceProperty) {
264+
} else if (data.propertyName === this.sourceOptions.property) {
265265
this.updateTarget(data.value);
266266
}
267267
}

0 commit comments

Comments
 (0)