Issue with repeater - query using contains & distinct

@russian-dima thanks a lot

I saw before the last post, but following the first post you sent me I changed my code. Still having an error although it’s a different one than before

ERROR MESSAGE: Wix code SDK error: The data parameter that is passed to the data method cannot be set to the value . It must be of type array


// For full API documentation, including code examples, visit https://wix.to/94BuAAs

import wixUsers from 'wix-users';
import wixData from 'wix-data';
import wixLocation from 'wix-location';
import { session } from 'wix-storage';

let userEmail;
let userId;
let titnomcirc

$w.onReady(function () {
    wixData.query("Members/PrivateMembersData")
    .eq("_id", wixUsers.currentUser.id)
    .find()
    .then((results) => {
      userEmail = results.items[0].loginEmail;
      userId = results.items[0]._id;
      $w('#text72').text = userEmail;
    });

titnomcirc = session.getItem("flagcircuito");
  $w('#nomcirc').text = titnomcirc


//cCODE CHANGED

$w.onReady(function () { myFunction() }); 
function myFunction () {

      wixData.query("clubbitComcategprod")
      .distinct("nomcateg")
 //.find()
      .then((results) => {
 if (results.items.length > 0) {
 let items = results.items;
 let firstItem = items[0];
 let length = results.length;
 let query = results.query;
          console.log(length)
          console.log(items)
          console.log(firstItem)
          console.log(query)
 
        $w('#repeater1').data = distinctList

 let distinctList = buildOptions(results.items)

$w("#repeater1").onItemReady(($item, itemData, index) => {
$item("#text71").text = itemData.nomcateg;
})

function buildOptions(items) {    
 return items.map(currentItem => {
 return { 
 label:currentItem, value:currentItem

     };
  });
}

      } else {}
 
      })
      .catch((error) => {
 let errorMsg = error.message;
 let code = error.code;
      });
 
}
});

@noanest
This is what you will need…
Yisrael gave the KEY for the closed DOOR!

https://www.wix.com/corvid/forum/community-discussion/retrieve-items-from-query-and-assign-to-repeater

Now you can modify first the DATA, before push it into REPEATER!
When you understood this, you will be able work with distinct.
Take a look one more time, what are the results after DISTINCT ?

After the DISTINCT-PROCESS the DATA has not the right FORMAT anymore to be add to the REPEATER. You have first to modify it → creating an OBJECT.
How to do that, you will find in the link given above.

REMEMBER —> the ERROR with the UNIQUE-ID ! ! ! !

@russian-dima thanks again and again man

Unfortunately I have the same error message as the last one. Probably it’s because of some stupid error I have in my code. To be honest, the last part added by you and Yisrael looks like the moon to me

// For full API documentation, including code examples, visit https://wix.to/94BuAAs

import wixUsers from 'wix-users';
import wixData from 'wix-data';
import wixLocation from 'wix-location';
import { session } from 'wix-storage';

let userEmail;
let userId;
let titnomcirc

$w.onReady(function () {
    wixData.query("Members/PrivateMembersData")
    .eq("_id", wixUsers.currentUser.id)
    .find()
    .then((results) => {
      userEmail = results.items[0].loginEmail;
      userId = results.items[0]._id;
      $w('#text72').text = userEmail;
    });

titnomcirc = session.getItem("flagcircuito");
  $w('#nomcirc').text = titnomcirc


//cCODE UPDATED

$w.onReady(function () { myFunction() }); 
function myFunction () {

      wixData.query("clubbitComcategprod")
      .distinct("nomcateg")
 //.find()
      .then((results) => {
 if (results.items.length > 0) {
 let items = results.items;
 let firstItem = items[0];
 let length = results.length;
 let query = results.query;
          console.log(length)
          console.log(items)
          console.log(firstItem)
          console.log(query)

 let myNewData = []
 for (var i = 0; i < results.items.length; i++) {     
          myNewData.push({"_id": items[i]._id, "message": items[i].message      
});
}

$w('#repeater1').data = [];         
$w('#repeater1').data = myNewData;


$w("#repeater1").onItemReady(($item, itemData, index) => {
$item("#text71").text = itemData.nomcateg;
})

      } else {}
 
      })
      .catch((error) => {
 let errorMsg = error.message;
 let code = error.code;
      });
 
}
})

@noanest

DO NOT USE onReady more then ONCE!
You make the same errors ^^

There were some little bugs in the code.
Perhaps you will have to improve and to modify it a little bit.
I deleted the repeater-function.
First let this part work. After you have got it to work, you can do the second step.

import wixUsers from 'wix-users';
import wixData from 'wix-data';
import wixLocation from 'wix-location';
import { session } from 'wix-storage';

let userEmail;
let userId;
let titnomcirc

$w.onReady(function () {
    wixData.query("Members/PrivateMembersData")
    .eq("_id", wixUsers.currentUser.id)
    .find()
    .then((results) => {
      userEmail = results.items[0].loginEmail;
      console.log(userEmail)
      userId = results.items[0]._id;
      console.log(userId)
      $w('#text72').text = userEmail;
    });

    titnomcirc = session.getItem("flagcircuito");
    $w('#nomcirc').text = titnomcirc

    { myFunction() });
})


function myFunction () {
    wixData.query("clubbitComcategprod")
    .distinct("nomcateg")
 //.find()
    .then((results) => {
 if (results.items.length > 0) {
 let items = results.items;
 let firstItem = items[0];
 let length = results.length;
 let query = results.query;
                console.log(length)
                console.log(items)
                console.log(firstItem)
                console.log(query)

 let myNewData = []
 for (var i = 0; i < length; i++) {     
                myNewData.push( {"_id": items[i]._id, "message": items[i].message} )    
            });
            console.log(myNewData)
        }
 else {  }
    });
    .catch((error) => {
 let errorMsg = error.message;
 let code = error.code;
    });
});

Take a carefuly look onto all CONSOLE-LOGS when CODE is running.

@russian-dima I changed the code. Now I do not have the error message. I paste the console.log below

@noanest
When you have no Errors and you get some RESULTS, then the CODE is WORKING FINE!

Now try to do the next step.

—> CONNECTING the REPEATER to the GIVEN RESULTS

This example may help you!

https://russian-dima.wixsite.com/meinewebsite/repeater-dropdown

But instead of…

$w('#repeater1').data = results.items

You use…

console.log(myNewData)
$w('#repeater1').data = [];         
$w('#repeater1').data = myNewData;

@russian-dima I have the same error message than before…also the repeater dissapears

There’s something else to be done in order for this to work. I don’t know what

I just added the following lines inside the IF, as shown in my previous code

$w('#repeater1').data = [] // IS THIS LINE NECESSARY ??
$w('#repeater1').data = myNewData;

$w("#repeater1").onItemReady(($item, itemData, index) => {
$item("#text71").text = itemData.nomcateg;
});

I copy console.log for myNewData and the error

Again, thanks a lot man, you took a lot of time on this

OK! Tomorrow i will reconstruct that shit xDDDDDD.
Now i want to know whats that shitty problem.
@Yisrael, perhaps he sees this post and has a good advise.

My ideas going out xD.
I have to test it on my own then, if nothing else works. :joy::sleeping:
But now is time to go to bed! :sweat_smile::sleeping:

I go sleep and you work on it. When i come back, everything works! xDDDD
See ya!

OK! I GOT IT! :nerd_face::nerd_face::nerd_face::nerd_face: after 3-days of trying and now about 3-hours of reconstructing and analysing ----> my dear, this will cost you a BEER!

Here you will find the reconstruction!
https://russian-dima.wixsite.com/meinewebsite/test-test-test

This post is connected with your issue / SOLUTION :grin:

P.S.: Do not forget to leave a BEST-ANSWER ! ! ! :rofl:

@russian-dima you got it man!!!
More than a beer I own you a beer…barrel
Lot of work on this, thank you very very much!!

I paste your link with the code solved
https://russian-dima.wixsite.com/meinewebsite/test-test-test

…and my console.log

You could already bring your own project to work ? :roll_eyes: That was fast ^^

More than a beer I own you a beer…barrel

Lot of work on this, thank you very very much!!
NOT AS MUCH AS HERE … :rofl: this woman kills me. No it’s not the women, it’s her project! XD
https://www.wix.com/corvid/forum/community-discussion/help-in-my-lightbox

@russian-dima …“When we finish this code, I want to communicate with you on Facebook😁” she says…way to go man

Anyhow, there should be a balance between “give me a hint on this code” & “code it for me, thank you very much”

In my case, when we got to this part of the code:

let myNewData = []
for ( var i = 0 ; i < results.items.length; i++) {
myNewData.push({ “_id” : items[i]._id, “message” : items[i].message

it became like chinese translated into mandarin. to much java maybe, and I have two months of coding now, so luckly I understand some corvid so far

Surely, I will be asking something else soon

Best,

@noanest
Everything ok, you know women are not the best in technical things :grin:.
Oh my, i hope i will not killed tomorrow , because of this sentence xD.

Yeah, i did not expect that, this turns into a bigger working project, but i already said YES, so just go truth and DO IT ! :rofl: (surely my last time xD)

Yes i know what you mean on this part oc code.
I hope i could make it a little bit more understandable on my site in the given example. :wink:

let myNewData = []for (var i = 0; i < results.items.length; i++) {               myNewData.push({"_id": items[i]._id, "message": items[i].message

Good luck with your further projects.
When you have spent about 6-Month on this forum (day by day), you will also be able understand a little bit more then now :grin:.

Nobody said, that it is an easy way! :sweat_smile: