I have a ratings input element(ratingsInput1) on my blog posts page. For each blog I want to capture a rating. How do I link the blog post ID to my ratings #Dataset1.
Here's my code.
$w.onReady( () => { $w("#dataset1").onReady( () => { let num= $w("#dataset1").getCurrentItemIndex(); console.log("OnReady---------- Done setting Ratings current item " + num + " ."); } ); $w("#dataset1").setCurrentItemIndex(3) .then( () => { console.log("OnReady---------- Done setting Ratings current item " + 3 + " ."); } ); } ); export function ratingsInput1_change_1(event) { $w("#dataset1").onReady(() => { // get the current item from the dataset const currentItem = $w("#dataset1").getCurrentItem(); let num=5; $w("#dataset1").setCurrentItemIndex(num); const currentItemidx = $w("#dataset1").getCurrentItemIndex(); console.log("==========On change Current Item index = " + currentItemidx + " ."); // get the current average rating, number of ratings, and //total ratings for the current dataset item const average = currentItem.avg; const count = currentItem.numRatings; const total = currentItem.totalRatings; // get the new rating from the ratings input const newRating = $w('#ratingsInput1').value; // calculate the new average rating based on the current //average and count const newAverageLong = (total + newRating) / (count +1); // Round the average rating to 1 decimal point const newAverageShort = Number.parseFloat(newAverageLong).toFixed(1); // set the dataset fields to the new average, total // ratings, and number of ratings $w('#dataset1').setFieldValues({ 'avg': newAverageShort, 'totalRatings': total + newRating, 'numRatings': (count + 1) }); // save the dataset fields to the collection $w('#dataset1').save() .catch((err) => { console.log('could not save new rating'); }); }); }
Wix Blog is a Wix app and it is only limited access for working with Corvid.
This is what you can currently do.
https://www.wix.com/corvid/example/custom-feed
https://www.wix.com/corvid/example/related-posts
These are the Wix Blog Collections that you have access to work with.
https://support.wix.com/en/corvid-by-wix/wix-blog-with-corvid
Wix Blog does already have a like count that you can access in code.
https://support.wix.com/en/article/corvid-wix-blog-posts-collection-fields#like-count-likecount-1
Like Count (likeCount)
Description: The number of likes the post received (from members only). Type: Number Can connect to data: Yes Can use in dynamic page URL: No Can be sorted: Yes Can be filtered: eq, ne, lt, lte, gt, gte Read-only: Yes
Note
Like Count data used on your site pages may require up to 24 hours to update. To make sure new post likes are included on your site in real time, disable caching for any page that uses Like Count data.
Note that disabling caching may increase your page loading time.
The like count can already be turned on and off on either desktop and mobile editor already in the Wix Blog settings.
Finally, note that the code sample you have used for your page is only intended to be used with the ratings element that is on the page, it isn't designed to be interjected with anything else.
https://support.wix.com/en/article/corvid-tutorial-capturing-and-displaying-ratings