mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Fixed issue when bindingContext is bound more than once.
This commit is contained in:
34
apps/tests/ui/bindingContext_testPage.ts
Normal file
34
apps/tests/ui/bindingContext_testPage.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import observableModule = require("data/observable");
|
||||
import pageModule = require("ui/page");
|
||||
|
||||
class MainViewModel extends observableModule.Observable {
|
||||
private _item: any;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.item = { Title: "Alabala" };
|
||||
}
|
||||
|
||||
get item(): any {
|
||||
return this._item;
|
||||
}
|
||||
|
||||
set item(value: any) {
|
||||
if (this._item !== value) {
|
||||
this._item = value;
|
||||
this.notifyPropertyChanged("item", value);
|
||||
}
|
||||
}
|
||||
|
||||
notifyPropertyChanged(propertyName: string, value: any) {
|
||||
this.notify({ object: this, eventName: observableModule.Observable.propertyChangeEvent, propertyName: propertyName, value: value });
|
||||
}
|
||||
}
|
||||
|
||||
var viewModel = new MainViewModel();
|
||||
|
||||
export function pageLoaded(args: observableModule.EventData) {
|
||||
var page = <pageModule.Page>args.object;
|
||||
page.bindingContext = viewModel;
|
||||
}
|
||||
Reference in New Issue
Block a user