question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Remove item which clicked an "X" button inside of it

See original GitHub issue

Hello. 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:open
  • Created 5 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

5reactions
chrishammcommented, Feb 11, 2019

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.

1reaction
chrishammcommented, Nov 22, 2018

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found