前提
フロントにNuxt、バックエンドにRailsを使用しています。
複数の値を一つのまとまりとしてidを振って管理しています。
グループとして値を使用するためにlong_term_id
というカラムでidを管理しています。
今回は複数のレコードを一気に消す必要が出てきたので、いい方法があれば教えて頂きたいです。
例えばlong_term_id
が1のもののみを削除したいです。
実現したいこと
・特定のidのみの値を複数抽出して、その値のみを削除したい。
該当のソースコード
js
1events:[ 2[{"id":142,"name":"","color":"#2196F3","start":1648797300000,"end":1648798200000,"timed":true,"long_time":true,"post_item_id":null,"post_id":null,"long_term_id":1,"created_at":"2022-04-01T16:02:15.584+09:00","updated_at":"2022-04-01T16:02:15.584+09:00"}, 3{"id":143,"name":"","color":"#2196F3","start":1648883700000,"end":1648884600000,"timed":true,"long_time":true,"post_item_id":null,"post_id":null,"long_term_id":1,"created_at":"2022-04-01T16:02:15.605+09:00","updated_at":"2022-04-01T16:02:15.605+09:00"}, 4{"id":144,"name":"","color":"#2196F3","start":1648970100000,"end":1648971000000,"timed":true,"long_time":true,"post_item_id":null,"post_id":null,"long_term_id":1,"created_at":"2022-04-01T16:02:15.614+09:00","updated_at":"2022-04-01T16:02:15.614+09:00"}, 5{"id":145,"name":"","color":"#2196F3","start":1649056500000,"end":1649057400000,"timed":true,"long_time":true,"post_item_id":null,"post_id":null,"long_term_id":1,"created_at":"2022-04-01T16:02:15.626+09:00","updated_at":"2022-04-01T16:02:15.626+09:00"}, 6{"id":146,"name":"","color":"#2196F3","start":1649142900000,"end":1649143800000,"timed":true,"long_time":true,"post_item_id":null,"post_id":null,"long_term_id":1,"created_at":"2022-04-01T16:02:15.637+09:00","updated_at":"2022-04-01T16:02:15.637+09:00"}, 7{"id":147,"name":"","color":"#2196F3","start":1648808100000,"end":1648809000000,"timed":true,"long_time":true,"post_item_id":null,"post_id":null,"long_term_id":147,"created_at":"2022-04-01T19:00:40.227+09:00","updated_at":"2022-04-01T19:00:40.227+09:00"}, 8{"id":148,"name":"","color":"#2196F3","start":1648894500000,"end":1648895400000,"timed":true,"long_time":true,"post_item_id":null,"post_id":null,"long_term_id":147,"created_at":"2022-04-01T19:00:40.246+09:00","updated_at":"2022-04-01T19:00:40.246+09:00"}, 9{"id":149,"name":"","color":"#2196F3","start":1648980900000,"end":1648981800000,"timed":true,"long_time":true,"post_item_id":null,"post_id":null,"long_term_id":147,"created_at":"2022-04-01T19:00:40.258+09:00","updated_at":"2022-04-01T19:00:40.258+09:00"},{"id":150,"name":"","color":"#2196F3","start":1649067300000,"end":1649068200000,"timed":true,"long_time":true,"post_item_id":null,"post_id":null,"long_term_id":147,"created_at":"2022-04-01T19:00:40.266+09:00","updated_at":"2022-04-01T19:00:40.266+09:00"}, 10{"id":151,"name":"","color":"#2196F3","start":1649153700000,"end":1649154600000,"timed":true,"long_time":true,"post_item_id":null,"post_id":null,"long_term_id":147,"created_at":"2022-04-01T19:00:40.274+09:00","updated_at":"2022-04-01T19:00:40.274+09:00"}, 11] 12
試したこと
・filterを使用してeachを使って削除しようと思いましたが、値が抽出できませんでした。
js
1const result = this.events.filter(v => v.long_term_id === 1)
・同じようにfindも利用しましたが、値を取得できませんでした。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。