Merge pull request #644 from NativeScript/nnikolov/BindingIssueWithNullSourceProperty

Fixed issue with binding when there is no sourceProperty set.
This commit is contained in:
Nedyalko Nikolov
2015-08-31 17:01:08 +03:00
2 changed files with 25 additions and 2 deletions

View File

@ -888,3 +888,21 @@ export function test_NestedPropertiesBindingTwoTargetsAndReplacingSomeNestedObje
TKUnit.assertEqual(target2.get("targetProp"), secondExpectedFirstName); TKUnit.assertEqual(target2.get("targetProp"), secondExpectedFirstName);
} }
export function test_NullSourcePropertyShouldNotCrash() {
var expectedValue = "Expected Value";
var target = new bindable.Bindable();
var convFunc = function (value) {
return value + "Converted";
}
var model = new observable.Observable();
model.set("field", expectedValue);
model.set("convFunc", convFunc);
target.bind({
sourceProperty: null,
targetProperty: "targetProp",
expression: "convFunc(field)"
}, model);
TKUnit.assertEqual(target.get("targetProp"), convFunc(expectedValue));
}

View File

@ -187,9 +187,14 @@ export class Binding {
return this.sourcePropertiesArray; return this.sourcePropertiesArray;
} }
private static getProperties(property: string) { private static getProperties(property: string): Array<string> {
if (property) {
return property.split("."); return property.split(".");
} }
else {
return [];
}
}
private resolveObjectsAndProperties(source: Object, propsArray: Array<string>) { private resolveObjectsAndProperties(source: Object, propsArray: Array<string>) {
var result = []; var result = [];