can't console.log items.length

The code below doesn’t print the temp.length in the preview console. Any idea why?

	wixData.query("ifc_data")
	   .ascending("Material CO2 footprint [tons]")
	   .find()
	   .then( (results) => {
	     var items = Object.values(results.items);
	     for (var index = 0; index < items.length; ++index) {
	     	var temp = items[index].split(',');
	     	console.log( temp.length );
     		}
	   } );

It seems like you have to redo your code. Try this. First of all this Material CO2 footprint [tons] can not be a valid fieldKey from your database. It is the fields key value you must insert here, not the name of the field.

wixData.query("ifc_data") 
.ascending("FIELDKEY HERE") 
.find() 
.then( (results) => { 
var items = results.items; 
console.log(items); // Make sure to console.log results first so that you know records is coming back
for (var index = 0; index < items.length; ++index) { 
  var temp = items[index].split(','); 	     	
  console.log( temp.length );
 }
 } );

Hope this will help you.

Hi Andreas,
I tried it using the key instead of the name, and I wrote the code exactly like you did, but it still isn’t printing the temp.length

For some reason also ‘items’ is an object with just everything together so instead of being
{ {item1}, {item2} }

its
{ item1, item2 }

but if I split() with ‘,’ then there will be no difference between item1 and item2.

Any clues to these issues?

Hi,
I followed up on this great link in order to shorten my switch-case statements:
https://toddmotto.com/deprecating-the-switch-statement-for-object-literals/

and after a bit of playing around I have this code which doesn’t work:

export function dropParameter_change(event, $w) {
	var selectedParameter = $w("#dropParameter").value;
	//console.log(selectedParameter); - prints correctly
	}
wixData.query("ifc_data")
	.ascending("totalCo2FootprintKg") //the correct key
	.find()
	.then((results) => {
		var items = results.items;
		//console.log(items); - prints correctly
		var parameter = getParameter(selectedParameter); //function to get dropdown selection
		console.log(parameter); //prints correctly
		for (var index = 0; index < items.length; ++index) {
	     	//console.log('test'); - prints correctly
	     	//console.log( items[index] ); - prints correctly
	     	var temp = items[index].split(',');
	     	console.log(temp); // doesn't print anything <--------- !
	        }
	});

Hi Yafim,
It’s a bit hard to inspect it without the whole code.
Can you please share a link to your site and specify the name of the page?
Roi.

Will you be able to see it like that? I thought you can only monitor the site via the Wix support team.

Items is the object with all the records in it so yes, it’s an array. Do you have commas inside the field value then? So you know that split will actually have something to spslit?

An example of the item is:

{“_id”:“727e8393-45c1-4ee5-9854-393ae0965f2e”,“architect”:“Example architect”, … }

So by splitting with ‘,’ I expect to get:

[ “_id”:“727e8393-45c1-4ee5-9854-393ae0965f2e”, “architect”:“Example architect”, … ]

and then to manipulate temp[0] further. Correct?

Ok I guess you want to split the records itself not the values inside a record?

You just can’t split an array that way. The code I wrote loops through the records one by one.

for (var index = 0; index < items.length; ++index) { 	     	   
console.log( items[index].title ); 
}

This code will loop through records and console log the title of each record. What do you want to do with the records. Try explaining why you try to split them.

Thanks Andreas!

I wasn’t aware I can access the record items this way. Now I used

items[index]._id 

and it gave me the item ID as I wanted.

My goal is to use the ID’s found and save them into an array in order to hide/show those items in a gallery.
The end goal is to hide/show items in the gallery depending on selections in the Dropdowns. I’m aware that many people try to achieve this but no coherent general solution was provided.

Do you know how I can ‘continuously’ check the status of a certain list of ID’s in order to always hide them from a gallery?