mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +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\i61.ts" />
|
||||||
<TypeScriptCompile Include="apps\ui-tests-app\pages\i73.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\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.d.ts" />
|
||||||
<TypeScriptCompile Include="file-system\file-name-resolver.ts">
|
<TypeScriptCompile Include="file-system\file-name-resolver.ts">
|
||||||
<DependentUpon>file-name-resolver.d.ts</DependentUpon>
|
<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;
|
var bindingSource = source;
|
||||||
if (!bindingSource) {
|
if (!bindingSource) {
|
||||||
bindingSource = this.bindingContext;
|
bindingSource = this.bindingContext;
|
||||||
|
binding.sourceIsBindingContext = true;
|
||||||
}
|
}
|
||||||
if (!types.isNullOrUndefined(bindingSource)) {
|
if (!types.isNullOrUndefined(bindingSource)) {
|
||||||
binding.bind(bindingSource);
|
binding.bind(bindingSource);
|
||||||
@ -102,8 +103,7 @@ export class Bindable extends dependencyObservable.DependencyObservable implemen
|
|||||||
for (var p in this._bindings) {
|
for (var p in this._bindings) {
|
||||||
binding = this._bindings[p];
|
binding = this._bindings[p];
|
||||||
|
|
||||||
var sourceIsNotBindingContext = (binding.source && (binding.source.get() !== oldValue));
|
if (binding.updating || !binding.sourceIsBindingContext) {
|
||||||
if (binding.updating || sourceIsNotBindingContext) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,6 +122,7 @@ export class Bindable extends dependencyObservable.DependencyObservable implemen
|
|||||||
export class Binding {
|
export class Binding {
|
||||||
options: definition.BindingOptions;
|
options: definition.BindingOptions;
|
||||||
updating = false;
|
updating = false;
|
||||||
|
sourceIsBindingContext: boolean;
|
||||||
source: WeakRef<Object>;
|
source: WeakRef<Object>;
|
||||||
target: WeakRef<Bindable>;
|
target: WeakRef<Bindable>;
|
||||||
|
|
||||||
|
@ -123,7 +123,10 @@ export class ListView extends view.View implements definition.ListView {
|
|||||||
|
|
||||||
public _getDefaultItemContent(index: number): view.View {
|
public _getDefaultItemContent(index: number): view.View {
|
||||||
var lbl = new label.Label();
|
var lbl = new label.Label();
|
||||||
lbl.text = this._getDataItem(index) + "";
|
lbl.bind({
|
||||||
|
targetProperty: "text",
|
||||||
|
sourceProperty: "$value"
|
||||||
|
});
|
||||||
return lbl;
|
return lbl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user