×

Please give details of the problem

Skip to content

How to use collection data in a List

Please read the tutorial How to: Create a backoffice to manage collections first.

Let's configure 2 linked lists : a list of car brands, and a list of car names from the selected brand.

linkedlist

As configured in the collection cars (cf tutorial), items are stored in that way:

2012-05-29_111809

The list of brands is already created : it's 'Car - brands'.

What we have to configure is a dynamic list of cars, that is populated from this collection every time the selected brand has changed.

In the dynamic list of cars, label will be 'Name' and the value will be 'Car ID'.

Let's configure a new webinterface 'Car Order':

Go to Collections tab:

  • plug the collection cars (1)
  • the identifier will be col_cars (2)

2012-05-29_145456

Go to Design tab:

2012-05-29_144328

  • Add a widget list Brand (1)
    • type custom list : select 'Car - brands'
    • value variable : brand_id
    • label variable brand_label
  • Add a widget list Name (2)
    • type variable based
    • value variable : car_id
    • label variable : car_name
    • List variable : vb_car*
  • Add a hidden split widget (3)
  • In this split widget add a widget js (4)
    • rename it 'listen brand_id'
    • Listen to variables : brand_id
    • Add the script below

Code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function list_ok(result) {

var vb_car = new Array();

for(i=0;i<result.length;i++) {

vb_car.push({"label":result[i].name,"value":result[i].car_id});

}

var a = new RMP_List();

a.fromArray(vb_car);

 RMPApplication.setList("vb_car",a);

}

function list_ko(result) {

//Error while retrieving cars from brand_id

alert("ko " + JSON.stringify(result));

}

var my_pattern = {};

my_pattern.brand_id = "[[brand_id]]";

col_cars.listCallback(my_pattern,{},list_ok,list_ko);

It's done. Give it a try!