Select to view content in your preferred language

Storing values from multiple select into definition expression

622
1
Jump to solution
01-27-2023 07:53 AM
TheGamer
Regular Contributor

So I have a multiple-select option and I was wondering how do I retrieve the values from the multi-select and assign it to the following layer expression:

 

map.allLayers.forEach((layer) => {
     layer.definitionExpression = "CSDNAME IN";
     layer.queryExtent().then(function (results) {
	       view.goTo(results.extent);
     });
});

 

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

You can get the values from the multi-select and turn them into a string, which would be then used in the definition expression

const options = document.getElementById('your-multi-select').selectedOptions;
const values = Array.from(options).map(({ value }) => "'" + value + "'");
//if the values are numbers, omit the quotes
//const values = Array.from(options).map(({ value }) => value);
const output = values.join();

layer.definitionExpression = "CSDNAME IN (" + output + ")";

View solution in original post

1 Reply
KenBuja
MVP Esteemed Contributor

You can get the values from the multi-select and turn them into a string, which would be then used in the definition expression

const options = document.getElementById('your-multi-select').selectedOptions;
const values = Array.from(options).map(({ value }) => "'" + value + "'");
//if the values are numbers, omit the quotes
//const values = Array.from(options).map(({ value }) => value);
const output = values.join();

layer.definitionExpression = "CSDNAME IN (" + output + ")";