So, I'm trying to make a list of items in a label. Should look like this:
Instead, its looking like this:
The arcade snippet:
function bullet(item, isLast){
return ' - ' + item + IIF(isLast, '', '\n');
}
function list(items){
var body = '';
for(var item in items){
var index = IndexOf(items, item);
var isLast = index == Count(items) - 1;
body += IIF(IsEmpty(item), '', bullet(item, isLast));
}
return body;
}
'<BOL>UND>' + 'test' + '</BOL></UND>\n' + list( ['hey', 'there'])
What would be the issue I'm missing?
Solved! Go to Solution.
This is the correction of the typo I had in my function. for(var i in items) i is actually the index, not the item.
function bullet(item, isLast){
return ' - ' + item + IIF(isLast, '', '\n');
}
function list(items){
var body = '';
for(var index in items){
var isLast = index == Count(items) - 1;
body += IIF(IsEmpty(item), '', bullet(items[index], isLast));
}
return body;
}
Is the list going to be drawing from a field or is it just going to be text in the arcade expression?
I'm going to be passing it a field. So something like this:
'<BOL>UND>' + $feature.field1 + '</BOL></UND>\n' + list( [$feature.field2, $feature.field3])
I was able to get it to work without the list function. To my knowledge I do not think that Arcade supports list functions. I wasn't able to find it in the ArcGIS Arcade documentation.
Here Arcade expression I was able to get to work with putting the values of the "list" on separate lines.
"<BOL>"+"<UND>"+$feature.field1+"</UND>"+"</BOL>" + TextFormatting.Newline + $feature.field2 + TextFormatting.Newline + $feature.field3
Let me know if you have any questions
gmattis_visalia wrote:
I was able to get it to work without the list function. To my knowledge I do not think that Arcade supports list functions. I wasn't able to find it in the ArcGIS Arcade documentation.
I think you may have missed part of the code. I have a function "list" defined above. It does a little bit of processing to see if the field has a value, and adds a bullet point to the field so its in a list-like format, like in the screenshot. The idea is, some fields may be empty or null, and I don't want them to have an empty bullet point, I'd rather they are skipped.
This is the correction of the typo I had in my function. for(var i in items) i is actually the index, not the item.
function bullet(item, isLast){
return ' - ' + item + IIF(isLast, '', '\n');
}
function list(items){
var body = '';
for(var index in items){
var isLast = index == Count(items) - 1;
body += IIF(IsEmpty(item), '', bullet(items[index], isLast));
}
return body;
}