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:
@ -1220,4 +1220,15 @@ export function test_BindingToRelatedProps() {
|
|||||||
model.prop2 = "Tralala";
|
model.prop2 = "Tralala";
|
||||||
|
|
||||||
TKUnit.assertEqual(target2.get('targetProp2'), "Tralala");
|
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;
|
||||||
}
|
}
|
@ -192,10 +192,8 @@ export class Binding {
|
|||||||
this.sourceOptions = undefined;
|
this.sourceOptions = undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bind(source: Object): void {
|
private sourceAsObject(source: any): any {
|
||||||
this.clearSource();
|
|
||||||
|
|
||||||
/* tslint:disable */
|
/* tslint:disable */
|
||||||
let objectType = typeof source;
|
let objectType = typeof source;
|
||||||
if (objectType === "number") {
|
if (objectType === "number") {
|
||||||
@ -208,6 +206,13 @@ export class Binding {
|
|||||||
source = new String(source);
|
source = new String(source);
|
||||||
}
|
}
|
||||||
/* tslint:enable */
|
/* tslint:enable */
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bind(source: Object): void {
|
||||||
|
this.clearSource();
|
||||||
|
|
||||||
|
source = this.sourceAsObject(source);
|
||||||
|
|
||||||
if (!types.isNullOrUndefined(source)) {
|
if (!types.isNullOrUndefined(source)) {
|
||||||
this.source = new WeakRef(source);
|
this.source = new WeakRef(source);
|
||||||
@ -559,7 +564,7 @@ export class Binding {
|
|||||||
let resolvedObj = objectsAndProperties[objectsAndProperties.length - 1].instance;
|
let resolvedObj = objectsAndProperties[objectsAndProperties.length - 1].instance;
|
||||||
let prop = objectsAndProperties[objectsAndProperties.length - 1].property;
|
let prop = objectsAndProperties[objectsAndProperties.length - 1].property;
|
||||||
return {
|
return {
|
||||||
instance: new WeakRef(resolvedObj),
|
instance: new WeakRef(this.sourceAsObject(resolvedObj)),
|
||||||
property: prop
|
property: prop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user