How to show code output in text?

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?

$w.onReady(function () {
    getData()
        .then((response) => {
 let subCount = response.items[0].statistics.subscriberCount;
            console.log(subCount);
            $w("#subCount").show();

As you can see my code it successfully running on the console but it’s not showing the output on the repeater text I connected.

  1. How can I get the database field item in the backend?
    As you can see I’m taking const but when I want to take database field item like this:
//const id = "****************";
var id = $w('title');

it’s not working & not giving any error too.

#database #backend #basics

Have you read the Wix API Reference for Repeater?
https://www.wix.com/corvid/reference/$w.Repeater.html

How do I populate a repeater with new data?
The most common way to populate a repeater is as follows:

  1. Set the repeater’s data using the data property. This triggers the second step for all items in the data array with a new ID.

  2. Populate the repeater with data from the new items using the onItemReady() function.

If you just want to call data from a dataset, then just use getCurrentItem from Wix Dataset.
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#getCurrentItem

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'
    });

All this code for the backend

#backend #database

@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'
    });

Any idea @givemeawhisky i’m waiting for your suggestion

@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'
    }); 


@jayitsvcool Again, look at how wixData.get() works in the documentation and look up return statements in the MDN Webdocs or hire a developer.