Hi ,
I am trying to figure out how I can use a Site variable to access as specific row in my dataset .
I have declared the Variable - counter on the site level
import {local} from ‘wix-storage’;
// …
local.setItem(“counter”, “9”);
On my page - I would like to display on a button the value of the 9 column - I have called this XXXX to highlight where I want to use it below .
I have tried both counter and value but neither of these worked
import {session} from ‘wix-storage’;
let y = session.getItem(‘counter’);
import wixData from ‘wix-data’;
import {local} from ‘wix-storage’;
let value = local.getItem(“counter”); // “value”
$w.onReady( function () {
});
export function button1_click(event) {
$w(“#dataset1”).getItems(XXXX, 1)
.then( (result) => {
let items = result.items;
$w(‘#button2’).value = items[0].aSaying
} )
. catch ( (err) => {
let errMsg = err.message;
let errCode = err.code;
} );
}
Can someone please point out where I am going wrong ?
Thanks
bob
console.log your variables to see what value you have set them to
Sorry, but it’s not clear to me what you are trying to do. What do you mean by the “9 column”? The getItems(from, count) function returns the count number of items starting at the from index. For example:
$w('#dataset1).getItems(9, 1);
returns one dataset item (database rows) starting at the ninth item (database row) in the dataset.
See the full description in the getItems() API documentation.
Hi ,
First up → Thanks for looking …
I am trying to use a variable instead of a specific number to select the database row.
so instead of this
$w('#dataset1).getItems(9, 1);
I want to be able to use
$w('#dataset1).getItems(MYVARIABLE, 1);
I have tried passing a variable but it doesnt work , I presumed it was because the variable was text but when I convert to a INT its the same .
Thanks
The value that’s retrieved from local storage is a string, and the getItems() function requires a number. You can convert it like this:
let value = Number(local.getItem("counter"));
If that doesn’t work, are you sure that something was saved in local storage? Try console.log() to see what you’re getting from local storage. Maybe there isn’t anything there.
Try something like this:
let value = local.getItem("counter");
console.log(value);
@yisrael-wix Thanks for that - it did the trick !