Last active
August 22, 2019 16:21
-
-
Save shanwixcode/9e4fcc7bbf6f0e3e8ae810e16205bfe3 to your computer and use it in GitHub Desktop.
Code to load data into Wix Gallery using a Dataset
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var obj = []; | |
export function dataset1_ready() { | |
let itemLength = $w("#dataset1").getTotalCount(); | |
$w("#dataset1").getItems(0, itemLength) | |
.then( (result) => { | |
let items = result.items; | |
aCoolFunction(items, itemLength); | |
}); | |
} | |
async function aCoolFunction(items, itemLength) { | |
await items.forEach( (item) => { | |
let data = { | |
type: "image", | |
description: item.description, | |
alt: item.altText, | |
title: item.title, | |
src: item.photo, | |
_id: item._id | |
} | |
obj.push(data); | |
}); | |
checkForCompletion(itemLength); | |
} | |
function checkForCompletion(itemLength) { | |
if(obj.length === Number(itemLength)) { | |
$w('#gallery1').items = obj; | |
} else { | |
console.log('Looping Function'); | |
checkForCompletion(itemLength); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment