I am trying to use the WixCode example to import a csv converted to json. I am getting value does not exist in#box1.
Here is the sample code:
Import Code
Select the Import button we created above and use the Properties panel to add an onClick event handler.
In the Page Code panel, add the code below to the event handler:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
export function importButton_onClick(event) {
const items = JSON.parse($w("#textBox").value);
const collection = $w("#collectionInput").value;
items.forEach( (item) => {
wixData.insert(collection, item)
.then( (results) => {
console.log(`Added item: ${JSON.stringify(results)}`);
} )
.catch( (err) => {
console.log(err);
} );
} );
$w("#textBox").value = "";
}
Here is my code:
import wixData from ‘wix-data’;
$w.onReady(function () {
//TODO: export function importButton_onClick(event) {
const items = JSON.parse($w(“#box1”).value);
const collection = $w(“input1”).value;
items.forEach( (item) => {
wixData.insert(collection, item)
.then( (results) => {
console.log(Added item: ${JSON.stringify(results)}
);
} )
.catch( (err) => {
console.log(err);
} );
} );
$w(“#textBox”).value = “”;
}
});
What am I doing wrong?