Database

I want to create BUY NOW button such that when a user clicks it the item from the database collection is removed. So can you help me out with the below code

import wixData from ‘wix-data’;

$w.onReady( function () {
//TODO: write your page related code here…
$w(“#dynamicDataset”).onReady( () => {

$w(“#button6”).onClick( (event) => {
let $item = $w.at(event.context);
let clickedItemData = $item(“#dynamicDataset”).getCurrentItem();
wixData.remove(‘ADDS’, clickedItemData)

  .then( (results) => { 

let item = results; //see item below
} )
. catch ( (err) => {
let errorMsg = err;
} );
} );
});
});

Hi Shubham ,

The Remove method is expecting to have collection’s name and an id .
So, your code should look something like this :

  let clickedItemData = $w("#dynamicDataset").getCurrentItem()._id; //to get the item ID
  wixData.remove("Collection'sName", clickedItemData ) 

Hope this helps!
Best,

Mustafa