how do i change dataprovider in a flex spark list that has itemrenderers?

In flex 4.5, I have an application that has a BorderContainer that loads a spark list (mxml style - _myList and the borderContainer is stored in a library outside of the parent application) that loads an arrayCollection with an itemRenderer (I should note said itemRenderer is not an inline renderer - on selection of an item in the list, the itemRenderer expands, loads a particular control within the item renderer based on data passed from the selected item in the list) and allows the user to perform a search. This works all well and good on startup/load, until I try to change the dataProvider for the list (my app allows users to switch data sources which then creates a new dataProvider with new variables). I have tried:

//app crashes
 _myList.dataProvider.removeAll();

//app crashes
_myList.dataProvider = new ArrayCollection();
_myList.dataProvider = acNew;(the new array collection to populate the list)

//app doesn't crash, but I can't get to any of the global variables upon 
//re-creation at the parent app level (even though I assigned it an id)
//so this is causing more headaches than I wanted

this.removeElement(_myList);
var searchList:SearchNew = new SearchNew();
searchList.percentWidth = 100;
searchList.percentHeight = 100;
searchList.id = "_myList";
searchList.setStyle("fontFamily","MyriadNoCFF");
searchList.g_appName = this.g_appName;
searchList.g_sessionID = this.g_sessionID;
searchList.g_TableID = this.g_tableID;
searchList.g_targetedLayer = this.g_tName;
searchList.g_testAC = new ArrayCollection();
searchList.g_item = <item/>;
searchList.g_req = <req/>;
searchList.g_sub_req = <req/>;
searchList.g_prev_where = <where/>;
searchList.g_prev_ws = <w/>;
searchList.g_breadcrumbsAC = new ArrayCollection();
searchList.g_controlType = "";          
searchList.itemRenderer = new ClassFactory(myItemRenderer);
searchList.dataProvider = acNew;
this.addElement(searchList);

I've tried _myList.dataGroup.invalidateDisplayList();, (_myList.dataProvider as ArrayCollection).refresh();.....none of these are working and the app just keeps on crashing.

Does anyone have any advice on how best to clear out the previous dataProvider and reassign the dataProvider based on a new arrayCollection of a spark list WITHOUT it crashing? Perhaps this has something to do with my itemRenderer? Should I be killing that off first?

I am new to using advanced itemRenderers. There's a sample here:

http://flexponential.com/2009/09/23/deleting-items-in-a-list-from-an-item-renderer/

that will do (kind of)what I want it to do (if instead of using removeItemAt, I use removeAll(), and a change of a list box value outside of all components mentioned kicks off the function instead of a click within the item renderer itself) except that it's an inline renderer and mine is not. I don't know how I would access the deleteItem() function from the borderContainer containing my list.

Any guidance would be greatly appreciated!


Does anyone have any advice on how best to clear out the previous dataProvider and reassign the dataProvider based on a new arrayCollection of a spark list WITHOUT it crashing?

This should work:

myList.dataProvider = myNewDataProvider;

If you only want to update a single item in the dataProvider you can update it it and then call itemUpdated() on the collection to force the renderer to refresh.

Perhaps this has something to do with my itemRenderer? Should I be killing that off first?

It is doubtful that your itemRenderer has anything to do with it, however without seeing the code behind it it is hard to say for sure. You may want to elaborate on what exactly happens when your app crashes. Do you get a runtime error? Or something else?

链接地址: http://www.djcxy.com/p/34620.html

上一篇: 如何在Spark列表中呈现DisplayObject实例的集合?

下一篇: 如何更改具有itemrenderers的柔性火花列表中的dataprovider?