Flex AdvancedDataGrid listItems 奇怪的行为
我有以下 XML,即高级 DataGrid 的数据提供者(作为 Hierarchicaldata):
public var reqData:XML = <root>
<Requirement ID="REQ-GEN-0.1" title="exigence gen 1" description="blabla 01" testable="true"/>
<RequirementSet ID="GUI REQ">
<Requirement ID="REQ-GUI-1.1" title="exigence ihm 1" description="blabla 11" testable="true"/>
<Requirement ID="REQ-GUI-1.2" title="exigence ihm 2" description="blabla 12" testable="false"/>
</RequirementSet>
<RequirementSet ID="PERF REQ">
<Requirement ID="REQ-PERF-2.1" title="exigence perf 1" description="blabla 21" testable="true"/>
<Requirement ID="REQ-PERF-2.2" title="exigence perf 2" description="blabla 22" testable="false"/>
<Requirement ID="REQ-PERF-2.3" title="exigence perf 3" description="blabla 23" testable="true"/>
<Requirement ID="REQ-PERF-2.4" title="exigence perf 4" description="blabla 24" testable="false"/>
<Requirement ID="REQ-PERF-2.5" title="exigence perf 5" description="blabla 25" testable="false"/>
<Requirement ID="REQ-PERF-2.6" title="exigence perf 6" description="blabla 26" testable="false"/>
</RequirementSet>
<RequirementSet ID="BUS REQ">
<RequirementSet ID="BUS 1 REQ">
<Requirement ID="REQ-BUS-3.1.1" title="exigence bus 1" description="blabla 311" testable="false"/>
<Requirement ID="REQ-BUS-3.1.2" title="exigence bus 2" description="blabla 312" testable="true"/>
</RequirementSet>
<RequirementSet ID="BUS 2 REQ">
<Requirement ID="REQ-BUS-3.2.1" title="exigence bus3" description="blabla 321" testable="true"/>
</RequirementSet>
<RequirementSet ID="BUS 3 REQ"/>
<RequirementSet ID="BUS 4 REQ">
<Requirement ID="REQ-BUS-3.4.1" title="exigence bus4" description="blabla 341" testable="false"/>
</RequirementSet>
<RequirementSet ID="BUS 5 REQ"/>
<RequirementSet ID="BUS 6 REQ"/>
</RequirementSet>
</root>;
这是 AdvancedDataGrid 部分:
<mx:AdvancedDataGrid id="reqADGtest" displayItemsExpanded="true"
width="95%" height="75%" horizontalCenter="0"
contentBackgroundAlpha="0.0" chromeColor="0xdbeaff"
openDuration="500" dragEnabled="true" dropEnabled="true"
dragMoveEnabled="true" editable="true"
variableRowHeight="true" horizontalScrollPolicy="auto">
<mx:columns>
<mx:AdvancedDataGridColumn dataField="@ID" headerText="ID"/>
<mx:AdvancedDataGridColumn dataField="@title" headerText="Titre"/>
<mx:AdvancedDataGridColumn dataField="@testable" headerText="Testable"/>
<mx:AdvancedDataGridColumn dataField="@description" headerText="Description"
editorUsesEnterKey="true"
wordWrap="true"/>
</mx:columns>
</mx:AdvancedDataGrid>
问题是,当我查看 AdvancedDataGrid 的 listItems 长度时,它在创建时为 19,然后是完全错误的 16 个(22 项)。我想访问一些项目但无法访问,这真的很烦人。这是一个错误还是什么?
注意:
要按 rowIndex 和 columnIndex 访问项目,我正在执行以下操作:
var advancedDataGridListData:AdvancedDataGridListData =
IDropInListItemRenderer(listItems[event.rowIndex][event.columnIndex]).listData
as AdvancedDataGridListData;
IHierarchicalCollectionView(dataProvider).getChildren(
advancedDataGridListData.item)
已编辑 23/02/2012
我使用 event.item 测试了您的解决方案,但不幸的是,该项目始终是null,我不明白为什么。所以我更深入地研究了AdvancedDataGridBaseEx的源代码,我发现这是Adobe源代码的一部分):
// send event to create the new one
var advancedDataGridEvent:AdvancedDataGridEvent =
new AdvancedDataGridEvent(AdvancedDataGridEvent.ITEM_EDIT_BEGINNING, false, true);
// ITEM_EDIT events are cancelable
advancedDataGridEvent.columnIndex = columnIndex;
advancedDataGridEvent.dataField = _columns[columnIndex].dataField;
advancedDataGridEvent.rowIndex = rowIndex;
dispatchEvent(advancedDataGridEvent);
你可以看到event.item从未被填充!!!!谢谢 Adobe...我会尝试您的其他解决方案,然后给您反馈。
最后编辑
我通过在自定义数据网格中使用解决了我的问题:
var xmlNode:XML = this.selectedItem as XML;
I have the following XML, that is the dataprovider (as a Hierarchicaldata) of an Advanced DataGrid:
public var reqData:XML = <root>
<Requirement ID="REQ-GEN-0.1" title="exigence gen 1" description="blabla 01" testable="true"/>
<RequirementSet ID="GUI REQ">
<Requirement ID="REQ-GUI-1.1" title="exigence ihm 1" description="blabla 11" testable="true"/>
<Requirement ID="REQ-GUI-1.2" title="exigence ihm 2" description="blabla 12" testable="false"/>
</RequirementSet>
<RequirementSet ID="PERF REQ">
<Requirement ID="REQ-PERF-2.1" title="exigence perf 1" description="blabla 21" testable="true"/>
<Requirement ID="REQ-PERF-2.2" title="exigence perf 2" description="blabla 22" testable="false"/>
<Requirement ID="REQ-PERF-2.3" title="exigence perf 3" description="blabla 23" testable="true"/>
<Requirement ID="REQ-PERF-2.4" title="exigence perf 4" description="blabla 24" testable="false"/>
<Requirement ID="REQ-PERF-2.5" title="exigence perf 5" description="blabla 25" testable="false"/>
<Requirement ID="REQ-PERF-2.6" title="exigence perf 6" description="blabla 26" testable="false"/>
</RequirementSet>
<RequirementSet ID="BUS REQ">
<RequirementSet ID="BUS 1 REQ">
<Requirement ID="REQ-BUS-3.1.1" title="exigence bus 1" description="blabla 311" testable="false"/>
<Requirement ID="REQ-BUS-3.1.2" title="exigence bus 2" description="blabla 312" testable="true"/>
</RequirementSet>
<RequirementSet ID="BUS 2 REQ">
<Requirement ID="REQ-BUS-3.2.1" title="exigence bus3" description="blabla 321" testable="true"/>
</RequirementSet>
<RequirementSet ID="BUS 3 REQ"/>
<RequirementSet ID="BUS 4 REQ">
<Requirement ID="REQ-BUS-3.4.1" title="exigence bus4" description="blabla 341" testable="false"/>
</RequirementSet>
<RequirementSet ID="BUS 5 REQ"/>
<RequirementSet ID="BUS 6 REQ"/>
</RequirementSet>
</root>;
And here is the AdvancedDataGrid part:
<mx:AdvancedDataGrid id="reqADGtest" displayItemsExpanded="true"
width="95%" height="75%" horizontalCenter="0"
contentBackgroundAlpha="0.0" chromeColor="0xdbeaff"
openDuration="500" dragEnabled="true" dropEnabled="true"
dragMoveEnabled="true" editable="true"
variableRowHeight="true" horizontalScrollPolicy="auto">
<mx:columns>
<mx:AdvancedDataGridColumn dataField="@ID" headerText="ID"/>
<mx:AdvancedDataGridColumn dataField="@title" headerText="Titre"/>
<mx:AdvancedDataGridColumn dataField="@testable" headerText="Testable"/>
<mx:AdvancedDataGridColumn dataField="@description" headerText="Description"
editorUsesEnterKey="true"
wordWrap="true"/>
</mx:columns>
</mx:AdvancedDataGrid>
The problem is that when I look at the listItems' length of the AdvancedDataGrid, it is 19 at the creation, and then 16 that is totally wrong (22 items). I want to access to some items and I can't which is really annoying. Is it a bug or something?
NOTE:
To access items by rowIndex and columnIndex I'm doing the following:
var advancedDataGridListData:AdvancedDataGridListData =
IDropInListItemRenderer(listItems[event.rowIndex][event.columnIndex]).listData
as AdvancedDataGridListData;
IHierarchicalCollectionView(dataProvider).getChildren(
advancedDataGridListData.item)
EDITED 23/02/2012
I tested your solution with event.item but unfortunatly this item was always null and I didn't understand why. So I looked deeper into the source code of AdvancedDataGridBaseEx and I found that this is a part of the Adobe source code):
// send event to create the new one
var advancedDataGridEvent:AdvancedDataGridEvent =
new AdvancedDataGridEvent(AdvancedDataGridEvent.ITEM_EDIT_BEGINNING, false, true);
// ITEM_EDIT events are cancelable
advancedDataGridEvent.columnIndex = columnIndex;
advancedDataGridEvent.dataField = _columns[columnIndex].dataField;
advancedDataGridEvent.rowIndex = rowIndex;
dispatchEvent(advancedDataGridEvent);
You can see that the event.item is never filled!!!! Thanks Adobe... I will try your other solution then I give you feedback.
LAST EDIT
I solved my problem by using in my custom datagrid:
var xmlNode:XML = this.selectedItem as XML;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
怎么样
这个dataProvider.getChildren(event.item)
基于这里的阅读, :
http://help.adobe .com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/AdvancedDataGridBaseEx.html#event:itemEditBeginning
或者也许是这样方法会有所帮助(尽管它是受保护的,因此您可能需要执行“猴子补丁”将访问控制修饰符从受保护更改为公共:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/AdvancedDataGridBaseEx.html#absoluteToVisibleIndices()
我认为关于 event.rowIndex 和事件.columnIndex 它本质上是为您提供绝对值,但 listItems 是基于当前可见的内容而不是绝对位置,我知道这不是直接答案,但它非常好。这里迟到了。
How about this
dataProvider.getChildren(event.item)
based on reading here:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/AdvancedDataGridBaseEx.html#event:itemEditBeginning
Alternatively maybe this method would help (though it's protected so you may need to do a "monkey patch" to change the access control modifier from protected to public:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/AdvancedDataGridBaseEx.html#absoluteToVisibleIndices()
I think on the event.rowIndex and event.columnIndex it's essentially giving you absolute values but the listItems has it based on what's currently visible rather than the absolute positions. Not a direct answer I know but it's very late here.