23 May 2011
Beginning
In this exercise you will apply the item renderer component created in Exercise 4.2: Displaying dynamic data in a custom item renderer to a Spark List control (see Figure 1). You will also use the same item renderer with a Spark ComboBox control.
This is another example of the flexibility of the Spark component architecture.
In this exercise, you will learn how to:
In this section, you will use the item renderer created in the previous exercise to render a Spark List control.
DataGroup control.DataGroup tags with List control tags.<s:List dataProvider="{employeeList}"
itemRenderer="components.EmployeeItemRenderer">
<s:layout>
<s:VerticalLayout/>
</s:layout>
</s:List>
You should see the black border of the List control surrounding the employees (see Figure 2).
In this section you will use the item renderer to display the employees in a Spark ComboBox control.
List block.List tags with ComboBox control tags.<s:ComboBox dataProvider="{employeeList}"
itemRenderer="components.EmployeeItemRenderer">
<s:layout>
<s:VerticalLayout/>
</s:layout>
</s:ComboBox>
ComboBox control. You should see the employees displayed with the item renderer, as shown in Figure 3.
ComboBox control.You should see the string [object Object] in the ComboBox control, as shown in Figure 4. This means that you need to define the property to display in the ComboBox control.
ComboBox control, add the labelField property with a value of lastName and add the width property with a value of 125.<s:ComboBox dataProvider="{employeeList}"
itemRenderer="components.EmployeeItemRenderer"
labelField="lastName"
width="125">
<s:layout>
<s:VerticalLayout/>
</s:layout>
</s:ComboBox>
ComboBox control. You should see the employee's last name displayed in the ComboBox control, as shown in Figure 5. Notice that the employee data is not centered within the ComboBox control.
BorderContainer tag, add the bottom, left, and right property with a value of 5.<s:BorderContainer borderWeight="2"
backgroundColor="#cccccc"
top="5" bottom="5" left="5" right="5"
height="100%" width="100%"/>
Notice the employee data is now centered within the ComboBox control (see Figure 6).
In this exercise you learned how to use an item renderer with a Spark List control and a Spark ComboBox control.
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.