Hi,
Right now I’m learning .js but I got stuck on this.
In regular code document.write shows the output on the page but on wix we have to use .show() so I have two very basic questions.
1.how can I show this code in the text of my repeater?
What whisky said, but also:
document.write and show() are completely different things.
.show(); is the Corvid equivalent to .style.visibility = ‘visible’;
Anything after double slashes is just a comment intended for humans - it is not read by the computer. //const id… does nothing
Use let instead of var . You can find plenty of resources on what the difference is if you want, but it’s just better practice.
$w is a selector , thus is used exclusively for front-end. Backend = server functions, and the server only delivers/receives data, it cannot read page elements.
Ok… Thanks… but can you explain why i’m getting error in this code
export async function getData() {
const apiKey = "xxxxxxxxxx";
//const id = "xxxxxxxxxxxxxxx";
// here i want to take field item from database & insert in the "id" so repeater shows every item
let id = $w("#title").id; // "myElement"
let response = await fetch("xxxxxxxxxxxxxxxx, {
method: 'get'
});
If I’ll find my old work from this website https://ipayzz.com/credit-card/ , I’ll tell you how to do that, but for now I can only recommend you to look for answers on youtube. I found solution there.
@jayitsvcool
What are you actually trying to achieve here?
When you say id, do you mean the site members own userid or a id that you are giving each site member etc?
Do you simply want to call data from a dataset and add it to the repeater for the current logged in site member only.
Or to show data from a specific site member who may or may not actually be logged in?
@givemeawhisky I’m trying to call data from a dataset & add it to repeater but for everyone.
I just one to know how can i take data from database for every repeater item
Like in the place const what should i write to take the data is this right?
const id = “xxxxxxxxxxxxx”; // in id i want to take my database title field data & here id is just use for data
let id = $w(“#mydatabase”).getCurrentItem().title; //is this correct
And when i’m trying to do this it shows the error wixcode error database does not exist.
Full Example i’m trying to code
import { fetch } from 'wix-fetch';
import wixData from 'wix-data';
export async function getData() {
const apiKey = "apikey";
const id = "asdahdkjafhk65156"; //example value | but when i'm putting the right value it works for one but i'm looking to get database data for every repeater item with different values. I hope you understand
let id = wixData.get('#myDatabaseName', 'title'); //Not working after deleting const id above
//imaginary url example below
const response = await fetch("https://www.exampleapi.com/data/d5/feed?&id=" + id + "&key=" + apiKey, {
method: 'get'
});
@vinnyvedici457 i searched a lot but not find anywhere please if you have the solution please let me know.
Full Example i’m trying to code
import { fetch } from 'wix-fetch';
import wixData from 'wix-data';
export async function getData() {
const apiKey = "apikey";
const id = "asdahdkjafhk65156"; //example value | but when i'm putting the right value it works for one but i'm looking to get database data for every repeater item with different values. I hope you understand
let id = wixData.get('#myDatabaseName', 'title'); //Not working after deleting const id above
//imaginary url example below
const response = await fetch("https://www.exampleapi.com/data/d5/feed?&id=" + id + "&key=" + apiKey, {
method: 'get'
});
@jayitsvcool wixData.get() requires an id to work in the first place. It gives you a single item in a collection, it does not give you results for the entire ‘title’ field.
You cannot declare id twice. Since you used const, id will always be “asdahdkjafhk65156”, and its new get() definition will only give you an error. You should search on the forum for how to pass data from the backend to the frontend. In order for it to work, you must use a return statement.
@skmedia Thank you for your comment but i think you misunderstood, the const id = “xxxx” is for show prupose here only not on the backend, when i declare let id = wixData.get(“myDatabaseName”, ‘title’) i already deleted the const id but the output is not showing on my repeater.
What should i do or what i’m doing wrong
Simply i want that let id will take the value from my database field value.
right now my backend look like this but its not showing any output in my repeater:
import { fetch } from 'wix-fetch';
import wixData from 'wix-data';
export async function getData() {
const apiKey = "apikey";
let id = wixData.get('#myDatabaseName', 'title'); //Not working after deleting const id above
//imaginary url example below
const response = await fetch("https://www.exampleapi.com/data/d5/feed?&id=" + id + "&key=" + apiKey, {
method: 'get'
});
@jayitsvcool Ok good. Then make sure you follow what I said about using get(). It doesn’t work the way you’re using it right now, it only works if you already have an _id.
@skmedia So how can I get title field values from my database to backend to show the output in frontend repeater I’m not able to understand, actually I’m confused here about what statement should I use here so it will start taking values from my database.
By the way when I’m using the below code it not showing any error but it also not showing any result to the repeater.
Now my backend code looks like this:
let callId = wixData.get("myDatabaseName", 'title');
//imaginary url example below
const response = await fetch("https://www.exampleapi.com/data/d5/feed?&id=" + id + "&key=" + apiKey, {
method: 'get'
});