加入孩子HierarchicalCollectionView [英] Add children to HierarchicalCollectionView
问题描述
我想实现延迟加载的助理总干事。而我被困在我需要返回的孩子加入到展开的节点的位置。
I'm trying to implement lazy loading on ADG. and I'm stuck in the point where I need to add the returned children to the expanded node.
目前我在做什么:
private function childrenloaded(data:*,item:*):void
{
var len:int = data.length;
for(var i=0;i<len;i++)
(internalMainGrid.dataProvider as HierarchicalCollectionView).addChild(item, data[i]);
}
这工作得很好,但它是缓慢的。 (21990毫秒共:919条记录) 有一些方法可以让我加快速度呢? - 喜欢直接设置儿童例如:
This works fine, but it is slow. (21,990 ms for total: 919 records) is there some way I can speed this up? - like setting children directly Ex:
var d:LazyHierarchicalData = (internalMainGrid.dataProvider as HierarchicalCollectionView).source as LazyHierarchicalData;
var ind:int = (d.source as RemoteCursorArray).getItemIndex(item);
(d.source as RemoteCursorArray)[ind].children = data;
(d.source as RemoteCursorArray).dispatchEvent(new CollectionEvent(CollectionEvent.COLLECTION_CHANGE));
但是,这并不令人耳目一新的观点。
But this is not refreshing the view.
任何帮助或方向朝着更好的解决方案是值得欢迎的。在此先感谢!
Any help or direction towards a better solution is welcome. Thanks in advance!
推荐答案
我已经做了同样的事情。从我发现 - 使用GroupingCollection(2)和/或的SummaryRow的真正减缓下来。更何况在一个特定节点获取新的数据时,整个树开闭复位。
I've done the same thing. From what I've found - using a GroupingCollection(2) and/or SummaryRow's really slows it down. Not to mention the entire tree open-close is reset when fetching new data at a particular node.
从烟测试中的表现,这将需要约5秒拉/油漆〜2000行。 现在大约需要1/2秒或更少100-200排在每个节点(不计算时,首先调用ADG屏幕初始油漆滞后)。
From smoke-test performance, it would take approx 5sec to pull/paint ~2000 rows. It now takes about 1/2sec or less for 100-200 rows at each node (not counting the initial paint lag when first calling the ADG to the screen).
对于我来说,我也做了以下内容:
For me, I have done the following:
- 扩展
HierarchicalData code>当孩子节点会存在的基础上汇总的数据我取从DB每次,并指定其属性包含要显示的孩子(如果自定义不同于儿童属性) - 我做的,因为我在的Robotlegs MVC平台上使用的模型了这一点。
- 延长
AdvancedDataGridGroupItemRenderer
在视觉上改变显示图标(三角形图形)的颜色 - 让用户知道哪些元素需要取主场迎战一个节点已经有数据。该分配给groupItemRenderer属性。 - 使用
AdvancedDataGridEvent.ITEM_OPEN
监听派遣包含event.item财产的事件,这样的命令>服务>响应更新了模型在所要求的精确点用户界面(增加了儿童属性)。 - 添加相应的
CollectionChangeEvent
的顶级集合(它的孩子们ArrayCollections - 嵌套集合不绑定) - 调用数据提供器的刷新方法后,响应者已宣布它是完整的。
- Extend
HierarchicalData
to customize when children nodes will exist based on summary data I fetch every time from the db, and to specify which property contains the children to be displayed (if different from the children property) - I do this because of the Models I use in a RobotLegs MVC platform. - Extend the
AdvancedDataGridGroupItemRenderer
to visually change the color of the disclosure icon (triangle graphic) - to let the user know which elements need to be fetched vs. a node that already has data. Assign this to the groupItemRenderer property. - Use
AdvancedDataGridEvent.ITEM_OPEN
listener to dispatch an event which contains the event.item property so that a command > service > responder updates the the model at the exact node requested by the UI (adding to the children property). - Add the appropriate
CollectionChangeEvent
to the top-level collection (it's children are ArrayCollections - nested collections are not binding) - Call the dataprovider refresh method after the responder has declared it's complete.
下面的伪例子:
//Listener on Grid:
protected function onLedgerOpenSummaryNode(event:AdvancedDataGridEvent):void
{
trace('LedgerMediator.onLedgerOpenSummaryNode', event.item);
if (event.item is SummaryTransaction)
{
refreshed = false;
sumTrans = event.item as SummaryTransaction;
//note - in my service responder I add the resulting db rows to the event.item
dispatch(new AccountEvent(AccountEvent.SUMMARY_DETAIL, null, account, event.item as SummaryTransaction));
}
}
//Dataprovider assignment to grid
private function get dataProvider():HierarchicalCollectionView
{
if (!groupCollection)
{
groupCollection = new HierarchicalCollectionView();
groupCollection.source = new OnDemandCollection();
}
return groupCollection;
}
//assigns the initial source to the demand collection
private function loadTransactions():void
{
var odc:OnDemandCollection = OnDemandCollection(dataProvider.source);
odc.source = account.summaryTransactions.children;
transactionChangeDetection(true);
view.callLater(deferrDataProviderUpdate);
}
//called when the service.responder dispatches it's 'complete event'.
private function deferrDataProviderUpdate():void
{
if (refreshed) return;
dataProvider.refresh();
}
//add change event listener to the top-level collection
private function transactionChangeDetection(add:Boolean):void
{
var collection:ArrayCollection;
//nested collections are not binding up the object chain, so change listeners must be added/removed to/from each collection.
for each ( var summary:SummaryTransaction in account.summaryTransactions.collection)
{
collection = summary.transactions.collection;
add ? collection.addEventListener(CollectionEvent.COLLECTION_CHANGE, onTransactionUpdate)
: collection.removeEventListener(CollectionEvent.COLLECTION_CHANGE, onTransactionUpdate);
}
}
//block the refresh method - only interested in add,delete,update
protected function onTransactionUpdate(event:CollectionEvent):void
{
if (event.kind == CollectionEventKind.REFRESH) return;
view.callLater(deferrDataProviderUpdate);
}
public class ExtAdvancedDataGridGroupItemRenderer extends AdvancedDataGridGroupItemRenderer
{
private var defaultColor:ColorTransform;
public function ExtAdvancedDataGridGroupItemRenderer()
{
super();
}
override protected function commitProperties():void
{
super.commitProperties();
if (disclosureIcon) defaultColor = disclosureIcon.transform.colorTransform;
}
override protected function updateDisplayList(w:Number, h:Number):void
{
super.updateDisplayList(w, h);
if (!listData || !data) return;
var adgld:AdvancedDataGridListData = AdvancedDataGridListData(listData);
var adg:AdvancedDataGrid = adgld.owner as AdvancedDataGrid;
var hcv:HierarchicalCollectionView = adg.dataProvider as HierarchicalCollectionView;
var source:IHierarchicalData = hcv.source;
var useDefaultColor:Boolean;
var visible:Boolean;
if (!data) visible = false;
else if (!source.canHaveChildren(data)) visible = false;
else if (source.hasChildren(data))
{
useDefaultColor = true;
visible = true;
}
else
{
visible = true;
var ct:ColorTransform = new ColorTransform();
ct.color = 0xBCB383;
disclosureIcon.transform.colorTransform = ct;
}
if (useDefaultColor) disclosureIcon.transform.colorTransform = defaultColor;
disclosureIcon.visible = visible;
}
}
public class OnDemandCollection extends HierarchicalData
{
public function OnDemandCollection()
{
super();
}
override public function getChildren(node:Object):Object
{
if (node is SummaryGrouping) return SummaryGrouping(node).children;
else if (node is SummaryTransaction) return SummaryTransaction(node).children;
else if (node is Transaction) return Transaction(node).children;
return {};
}
override public function canHaveChildren(node:Object):Boolean
{
if (node is SummaryGrouping)
{
return true;
}
else if (node is SummaryTransaction)
{
var sumTran:SummaryTransaction = SummaryTransaction(node);
return sumTran.numTransactions > 0;
}
else if (node is Transaction)
{
var tran:Transaction = Transaction(node);
return tran.isSplit;
}
else if (node is Split) return false;
else if (node.hasOwnProperty('children'))
{
var list:IList = node['children'] as IList;
return list.length > 0;
}
else return false;
}
}
这篇关于加入孩子HierarchicalCollectionView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!