views:

61

answers:

1

Hello Friends, I need to get the value of the item clicked and the name of the columns.

   for each(item in colunas) {

         var itemok:String = item.dataField;
         Alert.show(''+datagridlist.selectedItem.itemok); // show value of column

    }

But this way it returns 'undefined'.

But if I put the name already in function, I can get the correct data, example:

Alert.show(''+datagridlist.selectedItem.create); // create is a column name in mysql

But this variable must be created dynamically, example:

var itemok:String = item.dataField;
Alert.show(''+datagridlist.selectedItem.itemok); // show value of column

Could someone help me? I'm at it on time and I can not convert the string to column name.

I thank you all now

+1  A: 
for each(item in colunas) 
{
    var itemok:String = item.dataField;
    Alert.show(''+datagridlist.selectedItem[itemok]);
}

The dot syntax to access properties/fields works only with property names. When the property name is stored in a string, use square brackets.

var t:String = "value";
//The following three lines are the same and will work
trace(something.value);
trace(something["value"]);
trace(something[t]);

//but this one won't
trace(something.t);
Amarghosh
Thank you very muchsaved my nightThanks
luiz henrique