I tried adding user-generated content using the tutorial on the Wix YouTube channel, but the tutorial doesn’t show what I should connect my submit button to. What should I connect the button to?
The code I’ve used is:
import wixData from ‘wix-data’ ;
function getData ( ) {
let query = wixData . query [ ‘Comments’ ];
**return** query . limit ( 1000 ). find (). then ( results => {
console . log ( 'getData' , results );
**return** results . items ;
});
}
$w . onReady ( () => {
$w ( '#dataset2' ). onAfterSave ( () => {
getData (). then (( items ) => {
$w ( '#dataset3' ). data = items ;
});
});
});
Before you get some answers, you probably should first make a better description of your issue.
- Which tutorial you were following?
- Where is your current working (not working code) ???
- How do look like your database ?
- Do you use DATASETS, or Wix-Data (coding way) ???
Without all such important informations anybody will be able to help you!
Refill your post again.
@stc1705 Ok, after taking a look onto your code, i am able to say, that you must be relatively new to coding.
There are some issues in your code, also mixing DATASET-CODE with Wix-Data-code is not one of the best ideas. You better go either the one or the other way.
However, let’s switch to the issued code-lines…
This is aproxiatively how your code should look like…
import wixData from 'wix-data';
$w.onReady(async()=>{
let foundResults = await getData('Comments'); console.log("RESULTS: ", foundResults);
$w('#dataset2').onAfterSave(() => {
getData().then((items) => {
$w('#dataset3').data = items;
});
});
});
function getData() {
return wixData.query(DB)
.limit(1000)
.find()
.then((res)=>{return res;})
.catch((err)=>{console.log("ERROR occured!");});
}
- On top you have all library imports
- You always start your code with $w.onReady());
- Functions should always be placed either to the right related code-line ot to the very end of your code. (but not neccessary.
And my most important tip for you… always take a look onto the VELO-API, to get info of all currently used elements.
Whats going on here…?
$w('#dataset3').data = items; >--- maybe using a REPEATER here, would be better?)
Does .data somewhere exists inside dataset-api? Please check first.
But still something wrong with this code!!!
You said you need some actions when clicking the Submit-button ?
The action is already given and the SUBMIT-BUTTON even do not have to be coded.
You click the SUBMIT-BUTTON → some saving prozesses starts, right?
And what happens next?
$w('#dataset2').onAfterSave(() => {
getData().then((items) => {
$w('#repeater3').data = items;
});
});
Yes onAfterSave should run after saving-process.
Or i am today just overworked…to be continued! 
So what’s the last state here? Problem solved already ?