问题描述
我需要通过AS3获取所选行中某列的值,该怎么做?
I need to get the value of a certain column in the selected row via AS3, how can I do this?
当我尝试 grid.SelectedItem.text
...
感谢您的帮助!我需要能够通过名称引用列,在这种情况下为ID。
Thanks for the help! I need to be able to reference the column by name, in this case "ID".
编辑:这是否需要事件或某事?不应该有这种内置的方法?你会这样想的...
Does this require an event or something? Shouldn't there be a method for this built in? You'd think so...
推荐答案
你能更具体吗?
您可以使用selectedItem.yourProperty从DataGrid获取所需的所有数据。
你可以发布一个可能使事情清晰的片段吗?
You can get get all the data you need from the DataGrid using the selectedItem.yourProperty.Can you post a snippet that might make thing clear ?
以名称引用列很简单:
myDataGrid.getColumnAt(myDataGrid.getColumnIndex('ID'))
数据位于DataGrid的dataProvider中,该列位于其他目的。
The data is in the DataGrid's dataProvider, the column is there for other purposes.
说你有一个ID属性添加到DataGrid:
Say you have an ID property added to the DataGrid:
var dp:DataProvider = new DataProvider();
for(var i:int = 0 ; i < 7; i++)
dp.addItem({label:'label '+(i+1), ID:Math.random()});
myDataGrid.dataProvider = dp;
如果您为事件,您应该可以通过以下方式获取所需的数据
:
If you have setup a handler for the CHANGE event, you should be able to get the data you needthrough the selectedItem:
myDataGrid.addEventListener(Event.CHANGE, changed);
function changed(event:Event):void {
trace('item at index ' + myDataGrid.selectedIndex + ' has ID: ' + myDataGrid.selectedItem.ID);
}
HTH,
George
HTH,George
这篇关于Datagrid在特定列as3中选择行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!