- Сообщения
- 2 089
- Реакции
- 145
Hi guys!
Кто знает что написано в этой Китайской грамоте?
Кто знает что написано в этой Китайской грамоте?
Код:
//-------------Imports-------------//
// Import the wix-data module for working with queries.
import wixData from 'wix-data';
//-------------Global Variables-------------//
// Maximum number of charms that can be added to a bracelet.
const MAX_NUMBER_OF_CHARMS = 5;
// List of selected charms.
const selectedCharms = [];
// Map of bracelet product information.
let braceletsMap = {};
// Selected bracelet.
let selectedBracelet;
//-------------Page Setup-------------//
// Retrieve data when the page loads.
$w.onReady(async () => {
// Set a list of bracelet material types.
const braceletNames = ['Silver Bracelet', 'Rose Gold Bracelet', 'Gold Bracelet'];
// Query the collection for products whose name is one of the names from the bracelet names.
let newQuery = await wixData.query("Stores/Products").hasSome("name", braceletNames).find();
// Get the items from the query results.
const allBracelets = newQuery.items;
// Create the bracelet map based on the items returned by the query.
// For each item returned:
allBracelets.forEach(product => {
// Set the map key to the first part of the name (e.g. 'Silver Bracelet' becomes 'silver').
const keyName = product.name.split(' ')[0].toLowerCase();
// Set the corresponding map value to the product data.
braceletsMap[keyName] = product;
});
});
//-------------Repeater Setup-------------//
// Set up each item in the charms repeater as it is loaded.
export function charmsRepeater_itemReady($w, itemData, index) {
// Set the action that occurs when a user clicks the current charm image.
$w('#charmImage').onClick(() => {
// If the border is hidden, meaning the charm is being selected:
if ($w('#charmBorder').hidden) {
// Add the charm to the list of selected charms.
selectedCharms.push(itemData);
// Show the charm border, indicating it is now selected.
$w('#charmBorder').show();
// Add the selected charm to the bracelet image.
showCharmOnBracelet(itemData.mainMedia);
// Set the selected charms repeater in step 3 to reflect the charms that have been selected.
$w('#selectedCharmsRepeater').data = selectedCharms;
// If the user has now selected the maximum number of charms:
if (selectedCharms.length === MAX_NUMBER_OF_CHARMS) {
// Disable further charm selection.
disableCharmsSelection();
}
// If the border is not hidden, meaning the charm is being deselected:
} else {
// If further charm selection was disabled because the user had selected the maximum number of charms:
if (selectedCharms.length === MAX_NUMBER_OF_CHARMS) {
// Enable charm selection because an empty slot has opened up.
enableCharmsSelection();
}
// Find the index of the charm that is being deselected in the list of selected charms.
const indexOfCharm = selectedCharms.findIndex(item => item._id === itemData._id);
// Remove the charm that is being deselected from the list of selected charms.
selectedCharms.splice(indexOfCharm, 1);
// Set the selected charms repeater in step 3 to reflect the charms that are still selected.
$w('#selectedCharmsRepeater').data = selectedCharms;
// Remove deselected charm from the bracelet image.
hideCharmFromBracelet(itemData.mainMedia);
// Hide the charm border, indicating it is no longer selected.
$w('#charmBorder').hide();
}
});
}