Displaying data to dynamic pages

Hi, so I got my data base with contacts. I can display data dynamically using dataset, but I want to do it within the code.


I tried this but that didn’t work, so maybe I should do this with routers ? But should I write the above code into the router.js file ?

Thanks for your responses !

Just a guess. Presumably you are using a repeater to display your dataset information?

In this case you need to do a few things…

  1. Disconnect the dataset binding in the repeater and use the data property to load the repeater instead.
  2. In your then handler you should assign items to the repeater’s .data property.
  3. Once the data has been assigned you would then need to use either onItemReady or forEachItem handler to update the information in each repeater item view.

Don’t try to mix the usage of wixData and datasets as this will lead to insanity and make debugging a little tricky.

Hi, thanks for your answer, but to be clear I don’t use repeater. My page should be for a single user, and display content based on him.
Like his name, adress, mail, and other things that I will add later.

So I don’t think that I need this, what I want to do is just to code “Hi” + name in my code, depending on the url of the dynamic page.

I don’t know if that was clear

I just would like this answer if it would be possible!

Hi, thanks for your answer, but to be clear I don’t use repeater. My page should be for a single user, and display content based on him.
Like his name, adress, mail, and other things that I will add later.

So I don’t think that I need this, what I want to do is just to code “Hi” + name in my code, depending on the url of the dynamic page.

I don’t know if that was clear

Hi Yanis - perhaps a little more context is needed then.

Is this code running on a dynamic page?

Basically your query will load every Contact in your dataset (limited to a page size that defaults to 20) so you will need to filter it somehow using something like the logged in user information from wixMembers.

At the moment your query will load multiple contact records (try changing your console.log() to console.log(items retrieved: ${results.length}) to see how many).

What this means is that your map function will assign the firstName of each record to the same element finishing with the last record in the items list.

So in order to help you further you need to share what the page knows about when it loads.

Is the user logged in?
What user information do you keep in your Contacts data collection?
Why aren’t you using the membership data instead of your own (or is that a bad assumption on my part)?

Cheers

Just noted that you are using a dynamic page. So in this case, assuming the url for the page is derived from your Contacts collection, what you should do is grab the related Conract info from the page URL using wixLocation.path[0]

This is essentially what the dynamic page router uses to set up the dynamicData set which will already be filtered for you.

Once you have the path name you can build your query…

import wixLocation from “wix-location”;

let filterValue = wixLocation.path[0];

wixData. Query(“Contacts”).eq(,filterValue).find()…

will be the name of the column used in your dynamic query. So if this is the Contact ID property then would be “id”.

See if this helps.

@stcroppe

Thanks !

So this is what I did :

with the actual databse :

But in preview mode this is what I got :

I wonder how can I get no only the first name (inside filter tree → $and → 0) but also the others data from this contact (email, number …)

The fieldName is firstName not FirstName

@stcroppe I got the same result…

Sorry I meant fieldKey. That’s what you need to use

Thanks you ! That’s working !

One more thing, how can I actually make the text coming directly in the page ?
Cause I created a text, that I change :

The problem is that when I go on my page, there is first write “heading 3” then my code run and I got “Hello …”

I want my code to run directly without seeing “heading 3”, is there a way to do it ?

You may need to play with the rendering cycle in Wix-window/warmupdata

Hi !

The rendering cycle seems to be out of date and that it does not work anymore by seeing the doc.

So I tried with the rendering api and the env property, but nothing changed.

There is my code :

To be clear on what I want to do, my current problem is that when I launch my site, I first see “Heading 3” and then after 1 second, I got “Hello” (+ the name).

So I want to have directly my “Hello” (+ the name).