Remove item which clicked an "X" button inside of it
See original GitHub issueHello. I’ve got 5 items (i can dynamically ad new items) and i put a remove button inside of them. I want to remove item which clicked remove button inside of it. But always last item is being removed when i click a remove button.
here is my code.
<button @click="addItem">Add an item</button>
<grid-layout :layout="layout"
:col-num="12"
:row-height="30"
:is-draggable="draggable"
:is-resizable="resizable"
:vertical-compact="true"
:use-css-transforms="true"
>
<grid-item v-for="item in layout"
:x="item.x"
:y="item.y"
:w="item.w"
:h="item.h"
:i="item.i"
drag-allow-from=".window-header"
drag-ignore-from=".no-drag"
>
<div class="window">
<div class="window-header">Harita</div>
{{item.i}}
<button @click="removeItem">remove</button>
</div>
</grid-item>
</grid-layout>
this is code
`addItem: function() {
var self = this;
//console.log("### LENGTH: " + this.layout.length);
var item = {"x":0,"y":0,"w":2,"h":2,"i":this.index+"", whatever: "bbb"};
this.index++;
this.layout.push(item);
},
removeItem: function(item) {
console.log(item);
//console.log("### REMOVE " + item.i);
this.layout.splice(this.layout.indexOf(item), 1);
},
`
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:5
Top Results From Across the Web
how do i make my X button delete the specific object inside ...
You just need to get the index of the clicked task an give that index to deleteTask(). escape.addEventListener('click', function callback(e) ...
Read more >How to clear the list / remove an item? - Codecademy
1) Clear the entire page (e.g., a 2nd button at the top to “Reset”). and. 2) Remove a specific item (e.g., a “Remove...
Read more >The Button element - HTML: HyperText Markup Language
This attribute lets you associate <button> elements to <form> s anywhere in the document, not just inside a <form> .
Read more >How to remove an added list items using JavaScript
Approach: In the webpage, one input text box is given for the user entry to add a list item. Two buttons are given...
Read more >Add, copy, or remove a text box in Word - Microsoft Support
Insert text box button. If you select Draw Text Box, click in the document, and then drag to draw the text box the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

See https://github.com/chrishamm/vue-dynamic-grid and https://chrishamm.io/grid-demo/ I stopped using it though because the whole thing appears to be relatively slow (vue-grid-layout seems to be using absolute coordinates and a resize listener). IMHO there should be a better solution in the long term.
@spider58 I figured out why this did not work on my setup. You have to assign a static key to each grid-item, then it will work. You don’t seem to assign one at all anyway.