Populate Perspective-Dropdown

Hi,

I am using 8.0.1 perspective module and trying to populate a dropdown. I’ve notice that options is a dictionary with keys inside of a list. So doing this works:

dropdownNode = self.getSibling("DropdownNode").props.options
dict = {}
list = []

call = system.db.createSProcCall("cGetAllNodeIdAndLocation","Humidex_r")
system.db.execSProcCall(call)
ds = call.getResultSet()

for row in range(ds.getRowCount()):
	dict[row] = ds.getValueAt(row,"Location")		
	for key,val in dict.items():
		dropdownNode[row].value = key
		dropdownNode[row].label = val

I can populate the dropdown, but it will fail if I do not add array element first within the dropdown. So I tried to append this just for testing:

dropdownNode = self.getSibling("DropdownNode").props.options
list = []

list.append({"label": "hello", "value":2})
list.append({"label": "goodbye", "value":0})
dropdownNode = list

I get no errors with the bottom script in my logs on the gateway, but it doesn’t add a new array element inside the component.

This is the information returned by the stored procedure:

Id Location
1 D2ux Weld
2 RU Weld
3 KL Weld
4 C1E2 Weld
5 W Wax

Has anyone else ran into this?

You’re approaching this script as if dropdown node were a reference, when really it’s a value.

If you want to assign new dropdown options, you would want

l = []
l.append({'label':'hello','value':2})
l.append({'label':'goodbye','value':0})
self.getSibling('Dropdown').props.options = l

dropdownNode = self.getSibling('Dropdown').props.options only gets you the VALUE of that attribute - it does not store it as a reference for future manipulation.

Also, please don’t use list as a variable name; you can mask a lot of issues by using reserved words/types as variable names.

1 Like

Thank you!