mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
Fixed issue with simple object as binding context.
This commit is contained in:
@ -1221,3 +1221,14 @@ export function test_BindingToRelatedProps() {
|
||||
|
||||
TKUnit.assertEqual(target2.get('targetProp2'), "Tralala");
|
||||
}
|
||||
|
||||
export function test_only_Bindable_BindingContext_Null_DoesNotThrow() {
|
||||
var options: bindable.BindingOptions = {
|
||||
sourceProperty: "a.b",
|
||||
targetProperty: "test"
|
||||
}
|
||||
var obj = new bindable.Bindable();
|
||||
obj.bind(options);
|
||||
obj.bindingContext = new observable.Observable({ a: "b" });
|
||||
obj.bindingContext = null;
|
||||
}
|
@ -193,9 +193,7 @@ export class Binding {
|
||||
}
|
||||
}
|
||||
|
||||
public bind(source: Object): void {
|
||||
this.clearSource();
|
||||
|
||||
private sourceAsObject(source: any): any {
|
||||
/* tslint:disable */
|
||||
let objectType = typeof source;
|
||||
if (objectType === "number") {
|
||||
@ -208,6 +206,13 @@ export class Binding {
|
||||
source = new String(source);
|
||||
}
|
||||
/* tslint:enable */
|
||||
return source;
|
||||
}
|
||||
|
||||
public bind(source: Object): void {
|
||||
this.clearSource();
|
||||
|
||||
source = this.sourceAsObject(source);
|
||||
|
||||
if (!types.isNullOrUndefined(source)) {
|
||||
this.source = new WeakRef(source);
|
||||
@ -559,7 +564,7 @@ export class Binding {
|
||||
let resolvedObj = objectsAndProperties[objectsAndProperties.length - 1].instance;
|
||||
let prop = objectsAndProperties[objectsAndProperties.length - 1].property;
|
||||
return {
|
||||
instance: new WeakRef(resolvedObj),
|
||||
instance: new WeakRef(this.sourceAsObject(resolvedObj)),
|
||||
property: prop
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user