Filter if Value is an Array?

Hopefully, I described the title correctly.

Essentially, I have a dataset that tracks users who have applied to projects, then another dataset that tracks all projects. I need to create a table for each user that shows which projects they have applied for.

I think the issue is that in many cases, one user has applied to multiple projects. So, my query returns an array of projApplications and inturn the filter function cannot handle it unless it is a single value?

$w.onReady(function () {
	$w.onReady(function () {
	$w("#dynamicDataset").onReady(()=>{
		const userId = $w("#dynamicDataset").getCurrentItem()._owner;
		wixData.query("Project_Applications")
		.eq("_owner", userId)
		.find()
		.then( (results) => {
			let items = results.items;
			let projApplications = items.projId
		
		$w("#dataset1").setFilter(wixData.filter().hasSome("_id", userProj));
	});
	});
	});
});
1 Like

Hi, David,

you are actually on the right track.

You can use hasSome to get records matching any id in the given array. But you need to give it an array of ids.

Change

let projApplications = items.projId

To

let projApplications = items.map( item => item._id )

What this will do, is take array of items and map it to array of their ids.

Give it a try and let me know how it went!

4 Likes

Works like a charm! It was also something I never would’ve figured out without the help, so learning new stuff, slowly but surely.

Much appreciated Giedrius

4 Likes

Glad I could help. Have fun learning and Wix Coding! :slight_smile:

1 Like

Thanks So much it was so helpful i was so confused, and now i could solve mi problem.

1 Like
let arrayOfStuff = items.map( item => item._id )

I cant do this as i need to filter with a if then to remove items so can i add it to a rough and dirty array then do a hasSome filter?

HI i am sorry but i am not understand exactly your code , actual i am creating website
https://www.gowanderlocal.com/copy-of-home

here i set the checkboxgroup , i want to filter the value by mutliple check suppose here i want to filter by Social and Tourist Attractions so result will be display 2 values from the dataset

Can you please help me for this ?
Thank you
Jitendra

I Want to build a website similar to this https://swapse.com/
I was wondering if Wix could do this or would I be better to do it in Word Press?
What are the pros and cons? How big a database can I build?

Super helpful. Thank.