Well regarding your post, you are mixing up a few things and also your whole code do not realy look good. Why?
- Never use more than 1x $w.onReady() in your code.
- You are talking about ARRAY, but in fact you have an OBJECT as RESULT.
ARRAY = ["item1", "item2", "item3"]
OBJECT = {"firstname": "Elaine", "lastname": "Cadman"}
ARRAY of OBJECTS = [
{"firstname": "Elaine", "lastname": "Cadman"},
{"firstname": "Velo", "lastname": "Ninja"},
]
-
You are talking about a REPEATER, but at any place in your code you can find any repeater-code. Where is your repeater-code?
-
But wait, what is a REPEATER-TEXT-BOX?
First you should learn all the elements, before you start with more complicated things.
But i understand your needs, you want to get DUBLICATE-FREE-DATA out of your DATABASE.
Next to the distinct-function, there are also other ways of how to get UNIQUE-DATA, take a look onto the following example…
This is an excerpt of one of my own running codes, which generates unique DROP-DOWNS.
//--------------------- [ Create unique - Normal-Dropdowns ] -------------------------
function create_UniqueData(items, dbfield, txtField) {
const uniqueTitles = getUniqueTitles(items);
$w(txtField).text = buildOptions(uniqueTitles);
function getUniqueTitles(items) {
const titlesOnly = items.map(item => item[dbfield]);
return [...new Set(titlesOnly.sort())];
}
function buildOptions(uniqueTitles) {
return uniqueTitles.map(x => {
return {VALUE:String(x);};
});
}
}
So, let us use this example for your purposes…
import wixData from 'wix-data';
// ----------- USER-INTERFFACE ----------------------------------------
var database = "Wine";
var dbField = "country";
var txtField = "text1" ; //<---- the ID of your TEXT-BOX here......
// ----------- USER-INTERFFACE ----------------------------------------
$w.onReady(function () {
var items;
wixData.query(database)
.find()
//.distinct("country")
.then((results)=> {console.log("ARRAY-LENGTH: ", results.items.length);
if(results.items.length > 0) {console.log("Some COUNTRIES found!!!");
let items = results.items; console.log("ITEMS: ", items);
let firstItem = items[0]; console.log("FIRST-ITEM: ", firstItem);
create_UniqueData(items, dbField, txtField)
}
else {console.log("No COUNTRIES found!!!");}
})
.catch((error)=> {
let errorMsg = error.message;
let code = error.code;
console.log(errorMsg+" / "+code);
});
});
//--------------------- [ Create UNIQUE - DATA ] -------------------------
function create_UniqueData(items, dbfield, txtField) {
const uniqueTitles = getUniqueTitles(items); console.log("Unique-Data: ",uniqueTitles);
$w('#'+txtField).text = String(uniqueTitles);
function getUniqueTitles(items) {
const titlesOnly = items.map(item => item[dbfield]);
return [...new Set(titlesOnly.sort())];
}
}
Take also a look onto your CONSOLE! Working with console is the right way!
Of course you also can go the direct DISTINCT-WAY, this is just another way to success!
All you have to do, is to use the USER-INTERFACE, to put in your data. Do not touch all the other code-parts.