NativeScript Vue ListView onTap 不发送带有事件的项目
NativeScript Vue ListView onTap not sending item with event
所以我有一个 ListView,它使用 onTap 事件循环遍历数组对象。 onTap 事件触发了它应该触发的功能,但是当我尝试控制台记录 event.index 或 event.item,如文档中所列,我的应用程序崩溃并显示:
"JS ERROR TypeError: undefined is not an object (evaluating 'event.index')"
这是我遵循的文档:https://nativescript-vue.org/en/docs/elements/components/list-view/
这是相关的标记:
<ListView for="item in feed" @itemTap="onFeedItemTap()" class="background-gray">
<v-template>
<StackLayout class="feed-item-panel">
<StackLayout orientation="horizontal" style="padding: 5">
<Label class="feed-item" :text="item.Date" row="0" col="0" />
</StackLayout>
<StackLayout orientation="horizontal" style="padding: 5">
<Label class="feed-item bold" :text="'Product: ' + item.Product" fontAttributes="Bold" row="1" col="0" />
</StackLayout>
<StackLayout orientation="horizontal" style="padding: 5">
<Label :class="item.mostRecent" :text="item.info" row="2" col="0" textWrap="true" />
</StackLayout>
</StackLayout>
</v-template>
</ListView>
相关JS函数:
onFeedItemTap(event) {
console.log(event.index); //GIVES ERROR!!
this.$showModal(BBCard);
}
请让我知道我是否遗漏了什么,或者至少为我指明了正确的方向。但是从我看过的例子来看,这似乎是标准程序。
与{N}无关,纯属Vue。在文档中,他们不使用括号(方法事件处理程序)。此处默认获取事件对象。
<ListView for="item in listOfItems" @itemTap="onItemTap">
如果您使用括号(方法内联处理程序),则必须使用 $event
来授予对事件对象的访问权限
<ListView for="item in listOfItems" @itemTap="onItemTap($event)">
所以我有一个 ListView,它使用 onTap 事件循环遍历数组对象。 onTap 事件触发了它应该触发的功能,但是当我尝试控制台记录 event.index 或 event.item,如文档中所列,我的应用程序崩溃并显示:
"JS ERROR TypeError: undefined is not an object (evaluating 'event.index')"
这是我遵循的文档:https://nativescript-vue.org/en/docs/elements/components/list-view/
这是相关的标记:
<ListView for="item in feed" @itemTap="onFeedItemTap()" class="background-gray">
<v-template>
<StackLayout class="feed-item-panel">
<StackLayout orientation="horizontal" style="padding: 5">
<Label class="feed-item" :text="item.Date" row="0" col="0" />
</StackLayout>
<StackLayout orientation="horizontal" style="padding: 5">
<Label class="feed-item bold" :text="'Product: ' + item.Product" fontAttributes="Bold" row="1" col="0" />
</StackLayout>
<StackLayout orientation="horizontal" style="padding: 5">
<Label :class="item.mostRecent" :text="item.info" row="2" col="0" textWrap="true" />
</StackLayout>
</StackLayout>
</v-template>
</ListView>
相关JS函数:
onFeedItemTap(event) {
console.log(event.index); //GIVES ERROR!!
this.$showModal(BBCard);
}
请让我知道我是否遗漏了什么,或者至少为我指明了正确的方向。但是从我看过的例子来看,这似乎是标准程序。
与{N}无关,纯属Vue。在文档中,他们不使用括号(方法事件处理程序)。此处默认获取事件对象。
<ListView for="item in listOfItems" @itemTap="onItemTap">
如果您使用括号(方法内联处理程序),则必须使用 $event
来授予对事件对象的访问权限
<ListView for="item in listOfItems" @itemTap="onItemTap($event)">