javascript - NativeScript Vue ListView onTap 不发送带有事件的项目
问题描述
所以我有一个 ListView 循环通过一个带有 onTap 事件的数组对象。onTap 事件触发它应该触发的功能,但是当我尝试控制台记录 event.index 或 event.item 时,如文档中所列,我的应用程序崩溃说:
“JS ERROR TypeError:未定义不是对象(评估'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)">
推荐阅读
- javascript - 为什么使用忽略垃圾工件的方法替换段落内容不起作用?
- java - 使用 while 循环进行数据验证时出现问题
- python - 如何重定向输出
在python中将对象键入文本文件? - python - 使用邮递员的 GET 请求正在工作,但它不适用于 python (HTTPSConnectionPool)
- node.js - 有没有办法使用嵌套创建批量更新 prisma 中的对象
- vue.js - 是否可以使用 Vue.js 将数据从模板发送到脚本?(v-bind 的逆)
- c - 为什么我的第一个值没有正确打印,但后面的每个值都正确打印
- matlab - Matlab:风玫瑰情节:改变传说
- python - 从行中提取子行
- autosys - Autosys CA 用于触发 UNIX 脚本的应用程序协议