How to use collection data in a Array
First, read the tutorials:
Let's configure 2 linked lists in an array : in every row, a list of car brands (col1), and a list of car names from the selected brand (col2).
Creating linked lists in the array widget is the same as out of the array. You just have to set dynamically the variable name of the variable based lists.
An array widget is a set of columns. Each column has a specific widget type. As from a row to another on the same column, the content of the variable based list may be different, the variable names they rely on must be different.
The concept is to set dynamically the names :
Column 'Name' : 1st cell : vb_name = vb_car_0, 2nd cell : vb_name = vb_car_1 etc...
Create a new webinterface and add an array widget :
- variable my_cars
- identifier id_my_cars
- label: 'Brand'
- Type: 'Custom list'
- List : 'Car brands'
value variable: brand_id
- label variable: brand_label
- label: 'Name'
Type: 'Variable based'
List variable: vb_car (it won't be used. Just don't leave that field empty)
- value variable: name
label variable: car_id
label: 'js listen brand_id'
make it invisible
Listen to variable: my_cars.brand_id[P_index]
- Script as below
1 2 3 4 5 6
When the call to the collection is performed, it will then call &set_list_names or get_names_ko functions. Let's define them in a js widget included in a split widget at the bottom of the webinterface.
Label as 'js def' (1) and script as below (2):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
It's done : give it a try!