I've been trying to find an item in my dataset. Query seems like the best way. I just can't make it give me the results. If I do: results.items.toString() It gives me [object Object]. This is my code:
next.onClick( (event) => {
wixData.query("Consigners")
.eq("userId", id.value)
.find()
.then( (results) =>{
start.label = results.items.toString();
});
The console is to jumbled for me to find anything. I just changed a text label.
I even tried results.items[0].toString() and it gave me the same thing. Is it Query, or is it something else. Is there another way to search things?
I do have another question. How can I use code to change one field of one item in a dataset?
Hi Melanie,
To see what the query returns, use several console.log statements. You could keep adding console.log statements for each field if you want.
wixData.query("Consigners") .eq("userId", id.value) .find() .then( (results) =>{ //make object of first item of results. 0 is the first record, 1 the second, etc. let item = results.items[0]; // click on the ellipsis in the console to see the values of all the fields for that item (record) console.log(item); // to reference the field value it's simply item.fieldname console.log(item.title); console.log(item.lastName); });
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#setFieldValue