Add Like counters to multiple dataset items on same page?

Jeff,

That’s a good idea re implementation. You can use the wix-data update function to make that happen.

 import wixData from 'wix-data'; 
 
 export function likeClicked($w,event){

 //Do like animation here. You know, the one with the heart being filled in.

  let newPost= { 
 "_id": "00001", // Note the only required value is the ID
 "post_title": "Google Duplex will not take over!", 
 "author": "John Doe", 
 "likes": getLikeCount()+1 }; 
 //In reality you would implement getLikeCount() so it doesn't have to query DB
 //each time it wants to get likes.  
 
 //The update function is called with the following parameters:
 //update(name_of_collection: String, new_item_to_update_with: Object, [options:WixDataOptions]).
 //It returns a Promise with the newly added item.
 
 wixData.update("myCollection", newPost)
 .then( (results) => { let item = results;
      //Do whatever you need to do after the like has been sent to the DB.
  })
 .catch( (err) => { 
 
      //Catch any errors silently without affecting user experience.
      let errorMsg = err; 
  } ); 
  
  }