From 9677c6f6c32670e35f85cd069391485991573cf6 Mon Sep 17 00:00:00 2001 From: DrunkenPoney Date: Fri, 24 May 2019 14:42:00 -0400 Subject: [PATCH 1/2] fix(listview): fix ObservableArray items in ListView (#464) fix #464 --- .../nativescript/runtime/components/list-view.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/platform/nativescript/runtime/components/list-view.js b/platform/nativescript/runtime/components/list-view.js index 4e1db09d..c5a8bc7c 100644 --- a/platform/nativescript/runtime/components/list-view.js +++ b/platform/nativescript/runtime/components/list-view.js @@ -1,10 +1,12 @@ import { VUE_VIEW } from './v-template' import { extend } from 'shared/util' +import { ObservableArray } from 'tns-core-modules/data/observable-array' export default { props: { items: { - type: Array, + type: Object, + validator: val => Array.isArray(val) || val instanceof ObservableArray, required: true }, '+alias': { @@ -65,7 +67,7 @@ export default { methods: { onItemTap(args) { - this.$emit('itemTap', extend({ item: this.items[args.index] }, args)) + this.$emit('itemTap', extend({ item: this.getItem(args.index) }, args)) }, onItemLoading(args) { if (!this.$templates) { @@ -75,10 +77,7 @@ export default { const index = args.index const items = args.object.items - const currentItem = - typeof items.getItem === 'function' - ? items.getItem(index) - : items[index] + const currentItem = this.getItem(index) const name = args.object._itemTemplateSelector(currentItem, index, items) const context = this.getItemContext(currentItem, index) @@ -88,6 +87,11 @@ export default { }, refresh() { this.$refs.listView.nativeView.refresh() + }, + getItem(idx) { + return typeof this.items.getItem === 'function' + ? this.items.getItem(idx) + : this.items[idx] } } } From 9258d4412f1b72275ffc09c36c7bad530b41d005 Mon Sep 17 00:00:00 2001 From: DrunkenPoney Date: Fri, 24 May 2019 14:43:54 -0400 Subject: [PATCH 2/2] fix(samples): add sample for issue #464 ref #464 --- samples/app/464.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 samples/app/464.js diff --git a/samples/app/464.js b/samples/app/464.js new file mode 100644 index 00000000..8a6eb8ed --- /dev/null +++ b/samples/app/464.js @@ -0,0 +1,31 @@ +const Vue = require('./nativescript-vue') +const { + ObservableArray +} = require('tns-core-modules/data/observable-array/observable-array') + +Vue.config.debug = true +Vue.config.silent = false + +new Vue({ + data: { + items: new ObservableArray([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + }, + methods: { + onItemTap({ item }) { + this.items.push(`Item clicked: ${item} (shouldn't be \`undefined\`)`) + } + }, + template: ` + + + + + + + + + + + ` +}).$start()