Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***
- * POG - two-way
- * databind no dropdownlist
- * versao 0.1
- *
- */
- package components
- {
- import mx.collections.IList;
- import mx.controls.Alert;
- import mx.utils.ObjectUtil;
- import spark.components.DropDownList;
- public class myDropDownList extends DropDownList
- {
- public function myDropDownList()
- {
- super();
- }
- //Campo que será utilizado na pesquisa dentro do dataProvider
- [Bindable]
- public var keyField:String = "cCdId";
- //Campo usado para realizar o bind com a tabela.
- private var _keyValue:*;
- [Bindable]
- public function get keyValue():*
- {
- return _keyValue;
- }
- public function set keyValue(value:*):void
- {
- _keyValue = this.getKeyValue(value);
- }
- private function getKeyValue(value:*):*
- {
- if (value == null)
- {
- selectedIndex = -1;
- return;
- }
- for each (var obj:Object in dataProvider)
- {
- if (ObjectUtil.compare(obj[keyField].toString(), value) == 0)
- {
- selectedIndex = dataProvider.getItemIndex(obj);
- return obj[keyField].toString();
- }
- }
- }
- override public function set dataProvider(value:IList): void
- {
- super.dataProvider = value;
- if (keyValue != null)
- {
- keyValue = this.getKeyValue(selectedItem[keyField]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment