javascript - 拼接方法问题
问题描述
我正在从数组中删除一个元素:
this.my_events.splice(this.current_event);
this.current_event=null;
this.old_event=null;
jQuery('#eventModal').modal('hide');
当我在一个数组中添加三个或更多项目然后删除其中任何一个时,它会删除所有项目并返回 null 而不刷新页面。我正在使用Vue.js。
如果我随后刷新页面,则会显示这两个元素。这是什么问题?
解决方案
您没有指定要删除的索引位置。
尝试这个:
this.my_events.splice(index, 1); // the 1 represents how many items to delete
this.current_event=null;
this.old_event=null;
jQuery('#eventModal').modal('hide');
推荐阅读
- r - 您可以更改 facet_wrap 中每个特定图形的轴标签吗?
- reactjs - 带有 redux-persist 的 React-Router
- amazon-web-services - 按不是“文件夹”的 S3 对象键前缀对 Athena 进行分区
- java - Gradle 正在发布源代码和 Javadoc JAR,但不是源 JAR
- vue.js - 悬停文本字段时更改边框颜色
- vue.js - 使用 laravel paginate() 和 vuex 进行分页,
- amazon-s3 - 当每个文件进入我的 s3 存储桶时,如何为每个文件创建文件夹?
- html - 为什么分配的字体系列不会在移动设备上加载?
- javascript - 使用 JavaScript 将纯文本列表转换为 HTML 列表
- save - Pytorch 无法保存 torchvision 模型预训练的权重