I’m writing code to deal with ‘likes’, which involves adding the new like to fields on two databases. One of these, #dynamicDatasetupdates updates correctly but the other, #dataset2 doesn’t.
I access the correct file on dataset2 with this code:
$w ( “#dataset2” ). setFilter ( wixData . filter ()
. contains ( “email” , email ))
. then ( () => {
$w ( ‘#imageAuthor’ ). show ();
})
It finds the right file because the correct image is displayed. The dataset is set to read-write.
Here is the code to update both the databases:
// add or remove a like
export function buttonClicked_click () {
let itemObj1 = $w ( “#dynamicDataset” ). getCurrentItem ();
let itemObj2 = $w ( “#dataset2” ). getCurrentItem ();
bookID = itemObj1 . _id ;
likesDB1 = itemObj1 . likes ;
likesDB2 = itemObj2 . likes ;
**if** ( liked === 0 )
{
**let** plusLikes1 = itemObj1 . likes + 1 ;
**let** plusLikes2 = itemObj2 . likes + 1 ;
$w ( "#dynamicDataset" ). setFieldValue ( 'likes' , plusLikes1 );
$w ( "#dynamicDataset" ). save ();
$w ( "#dataset2" ). setFieldValue ( 'likes' , plusLikes2 );
$w ( "#dataset2" ). save ();
$w ( "#heart" ). show ();
liked = 1 ;
}
As I said, #dynamicDataset works fine and the heart symbol shows, but #dataset2 doesn’t save the value. Strangely, I put a text field on the page connected to the likes field on the database and this changes correctly when the like button is clicked - I would have thought that means the database has been updated, as it’s picking up the new value from there - isn’t it?
Can someone help me untangle this?