mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
Fixed issue with binding context in a list view scenario.
This commit is contained in:
@ -198,6 +198,7 @@
|
||||
<TypeScriptCompile Include="apps\ui-tests-app\pages\i61.ts" />
|
||||
<TypeScriptCompile Include="apps\ui-tests-app\pages\i73.ts" />
|
||||
<TypeScriptCompile Include="apps\ui-tests-app\pages\gestures.ts" />
|
||||
<TypeScriptCompile Include="apps\ui-tests-app\pages\listview_binding.ts" />
|
||||
<TypeScriptCompile Include="file-system\file-name-resolver.d.ts" />
|
||||
<TypeScriptCompile Include="file-system\file-name-resolver.ts">
|
||||
<DependentUpon>file-name-resolver.d.ts</DependentUpon>
|
||||
|
23
apps/ui-tests-app/pages/listview_binding.ts
Normal file
23
apps/ui-tests-app/pages/listview_binding.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import pageModule = require("ui/page");
|
||||
import gridLayoutModule = require("ui/layouts/grid-layout");
|
||||
import listViewModule = require("ui/list-view");
|
||||
import observable = require("data/observable");
|
||||
import observableArr = require("data/observable-array");
|
||||
|
||||
var arr = new observableArr.ObservableArray();
|
||||
for (var i = 0; i < 100; i++) {
|
||||
arr.push("item " + i);
|
||||
}
|
||||
|
||||
export function createPage() {
|
||||
var page: pageModule.Page = new pageModule.Page();
|
||||
var grid: gridLayoutModule.GridLayout = new gridLayoutModule.GridLayout();
|
||||
var listView: listViewModule.ListView = new listViewModule.ListView();
|
||||
listView.on(listViewModule.ListView.loadedEvent, function (args: observable.EventData) {
|
||||
(<any>args.object).items = arr;
|
||||
});
|
||||
grid.addChild(listView);
|
||||
page.content = grid;
|
||||
|
||||
return page;
|
||||
}
|
@ -49,6 +49,7 @@ export class Bindable extends dependencyObservable.DependencyObservable implemen
|
||||
var bindingSource = source;
|
||||
if (!bindingSource) {
|
||||
bindingSource = this.bindingContext;
|
||||
binding.sourceIsBindingContext = true;
|
||||
}
|
||||
if (!types.isNullOrUndefined(bindingSource)) {
|
||||
binding.bind(bindingSource);
|
||||
@ -102,8 +103,7 @@ export class Bindable extends dependencyObservable.DependencyObservable implemen
|
||||
for (var p in this._bindings) {
|
||||
binding = this._bindings[p];
|
||||
|
||||
var sourceIsNotBindingContext = (binding.source && (binding.source.get() !== oldValue));
|
||||
if (binding.updating || sourceIsNotBindingContext) {
|
||||
if (binding.updating || !binding.sourceIsBindingContext) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -122,6 +122,7 @@ export class Bindable extends dependencyObservable.DependencyObservable implemen
|
||||
export class Binding {
|
||||
options: definition.BindingOptions;
|
||||
updating = false;
|
||||
sourceIsBindingContext: boolean;
|
||||
source: WeakRef<Object>;
|
||||
target: WeakRef<Bindable>;
|
||||
|
||||
|
@ -123,7 +123,10 @@ export class ListView extends view.View implements definition.ListView {
|
||||
|
||||
public _getDefaultItemContent(index: number): view.View {
|
||||
var lbl = new label.Label();
|
||||
lbl.text = this._getDataItem(index) + "";
|
||||
lbl.bind({
|
||||
targetProperty: "text",
|
||||
sourceProperty: "$value"
|
||||
});
|
||||
return lbl;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user