Merge pull request #295 from NativeScript/nnikolov/BindingNestedPropertiesIssue

Fixed issue with updating nested properties via binding.
This commit is contained in:
Nedyalko Nikolov
2015-06-08 13:52:40 +03:00
2 changed files with 33 additions and 1 deletions

View File

@ -542,3 +542,35 @@ export function test_BindingToDictionaryAtAppLevel() {
helper.buildUIAndRunTest(createLabel(), testFunc);
}
export function test_UpdatingNestedPropertyViaBinding() {
var expectedValue1 = "Alabala";
var expectedValue2 = "Tralala";
var viewModel = new observable.Observable();
var parentViewModel = new observable.Observable();
viewModel.set("parentView", parentViewModel);
parentViewModel.set("name", expectedValue1);
var testElement: bindable.Bindable = new bindable.Bindable();
testElement.bind({
sourceProperty: "parentView.name",
targetProperty: "targetName",
twoWay: true
}, viewModel);
var testElement2: bindable.Bindable = new bindable.Bindable();
testElement2.bind({
sourceProperty: "parentView.name",
targetProperty: "targetProperty",
twoWay: true
}, viewModel);
TKUnit.assertEqual(testElement.get("targetName"), expectedValue1);
testElement.set("targetName", expectedValue2);
TKUnit.assertEqual(parentViewModel.get("name"), expectedValue2);
TKUnit.assertEqual(testElement2.get("targetProperty"), expectedValue2);
}

View File

@ -261,7 +261,7 @@ export class Binding {
else {
this.updateTarget(expressionValue);
}
} else if (data.propertyName === this.options.sourceProperty) {
} else if (data.propertyName === this.sourceOptions.property) {
this.updateTarget(data.value);
}
}