2012-03-22 36 views
0

我正在使用'Tilelist'和'HBOX'作爲itemrenderer。在HBOX中我有複選框。帶有複選框的Itemrenderer中的選擇不正確

將arraycollection作爲dataprovider傳遞給TileList(我的arraycollection長度爲20)。在選擇Tilelist中item1的複選框並滾動列表時,我可以看到隨後的item從item1被選中。在我發現的博客中,使用複選框時存在一些彈性緩存問題。

需要一些幫助。

預先感謝您。

<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" verticalGap="0" xmlns:local="*" height="500" > 
    <mx:Script> 
    <![CDATA[ 
     private var arr:Array = [ 
      { firstName: "Alex", lastName: "Harui" }, 
      { firstName: "Gordon", lastName: "Smith" }, 
      { firstName: "Deepa", lastName: "Subramanian" }, 
      { firstName: "Matt", lastName: "Chotin" }, 
      { firstName: "Ely", lastName: "Greenfield" }, 
      { firstName: "Kevin", lastName: "Lynch" }, 
      { firstName: "Shantanu", lastName: "Narayan" }, 
      { firstName: "Joan", lastName: "Lafferty" }, 
      { firstName: "Ryan", lastName: "Frishberg" }, 

     ]; 

    ]]> 
    </mx:Script> 
    <mx:TileList id="list" initialize="list.dataProvider=arr" labelField="lastName" maxColumns="1" itemRenderer="Checkrenderer" 
       allowMultipleSelection="true" > 

    </mx:TileList> 
</mx:Application> 

Checkrender HBOX:

<?xml version="1.0" encoding="utf-8"?> 
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" width="138" height="300" xmlns:local="*"> 
<mx:CheckBox id="checkbx"/> 
</mx:Box> 
</mx:HBox> 
+1

是否使用項目渲染器?你能發佈你的代碼嗎?你可能需要重寫'public function set data(value:Object)' – 2012-03-22 15:59:35

+0

\t user1285835 2012-03-22 16:36:43

+0

Checkrenderer代碼: \t \t \t的 \t <本地:CheckBoxRenderer ID = 「checkbx」/> \t – user1285835 2012-03-22 16:38:02

回答

0

基本上你需要跟蹤在dataProvider中的數據所選擇的價值,這是由於該項目渲染器「回收」,意味着它們是重複使用應用的不同數據,以便跟蹤給定行的實際選定值,需要將其附加到與該行關聯的數據。您可以使用下面的示例中提供的名爲ValueObjectWithSelected的類,通過將其分配給value屬性來「包裝」任何其他VO/DTO,選定的屬性用於跟蹤複選框選擇,並且呈示器在複選框選中的值會更改。

http://www.shaunhusain.com/CheckboxList/

http://www.shaunhusain.com/CheckboxList/srcview/

要解決你的具體情況:

<?xml version="1.0" encoding="utf-8"?> 
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" width="138" height="300" xmlns:local="*"> 
    <mx:CheckBox id="checkbx" label="{data.firstName}" change="{data.selected = checkbx.selected}" selected="{data.selected}"/> 
</mx:HBox>