开发者

How to convert a String into the property name of an object in Flex

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


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜