Skip to content

Instantly share code, notes, and snippets.

@Synvox
Last active March 15, 2018 02:17
Show Gist options
  • Save Synvox/d29ef66bf6629ebae5615624003a1371 to your computer and use it in GitHub Desktop.
Save Synvox/d29ef66bf6629ebae5615624003a1371 to your computer and use it in GitHub Desktop.
import wixData from 'wix-data';
/*
steps:
1. Get the order you need
2. Get a list of images that can be clicked
3. for each image, add a click event
4. In each click event, update the order
from step 1 to be the id from the image
The hardest part will be associating each image
with the item in the collection.
*/
// onReady is called when the page is finished loading.
$w.onReady(async ()=>{
// ^^^^^
// Important! async enables the await keyword.
// This makes promises not so bad.
const orderId = '---somehow get the order id---'
// get the order before anything else happens.
const order = await wixData.get('orders', orderId)
const pictures = [
// You need to get all the picture elements
// e.g.:
$w('#picture1'),
$w('#picture2'),
///...
]
// note
// you'll probably need to visually change the picture
// that is currently selected. You have the pictures in
// an array, and you have the selected picture in the
// variable named 'order' (e.g.: order.picture)
pictures.forEach((picture)=>{
// 'picture' is now set to the actual image on the
// screen. It is not the item in your collection.
// You'll need to get the _id of the item somehow.
picture.onClick = async ()=>{
// This will not work. Replace 'picture' with the
// id of the item in the collection.
order.picture = picture
await wixData.update('orders', order)
// note
// this will not change the page visually. You'll
// need to add something visually to the image here
// so it shows the updated selection.
}
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment