Fixed issue with binding when there is no sourceProperty set.

This commit is contained in:
Nedyalko Nikolov
2015-08-31 15:49:42 +03:00
parent 9203850ea7
commit fc3c52691e
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);
}
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;
}
private static getProperties(property: string) {
private static getProperties(property: string): Array<string> {
if (property) {
return property.split(".");
}
else {
return [];
}
}
private resolveObjectsAndProperties(source: Object, propsArray: Array<string>) {
var result = [];