关于HorizontalList值绑定改变的问题。求解。

生活 2011-03-09 02:03:15
Main.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="init();">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import asfiles.UserInfo;

import mx.collections.ArrayCollection;

[Bandable]
private var uInfo:UserInfo;

[Bandable]
private var arr:ArrayCollection = new ArrayCollection();

private function init():void
{
uInfo = new UserInfo();
uInfo.userName = "xiaowang";
uInfo.age = 25;
arr.addItem(uInfo);
}
private function updateArr():void
{
if(arr.length>0)
{
for(var i:int=0; i < arr.length;i++ )
{
var cu:UserInfo = arr[i] as UserInfo;
cu.userName = "xiaoli";
cu.age = 11;
}
}
}

]]>
</fx:Script>
<s:BorderContainer backgroundColor="0x000000">
<mx:HorizontalList id="horizontalList"
borderAlpha="0.0"
dataProvider="{arr}"
itemRenderer="faceimage"
labelField="label"
iconField="thumbnailImage"
liveScrolling="true"
columnWidth="175"
columnCount="3"
selectedIndex="0"
rowCount="1"
rowHeight="100"
showScrollTips="true"
horizontalScrollPolicy="on"
/>
</s:BorderContainer>
<s:Button x="361" y="185" label="update" click="updateArr();"/>

</s:Application>

UserInfo.as
package asfiles
{
public class UserInfo
{
public var userName:String;
public var age:int;

public function UserInfo()
{
}
}
}

faceimage.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" maxWidth="76" height="63" width="110">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Label text="{data.userName}" x="17" y="35" height="24"/>
<s:Label text="{data.age}" x="17" y="10"/>
</mx:Canvas>

update按钮是更新信息,但是在HorizontalList里面的值就是不改变不知道什么情况,求救!
...全文
37 2 打赏 收藏 举报
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
xlgp2171 2011-03-09
在方法之前执行horizontalList.invalidateList();
修改为:
private function updateArr():void
{
if(arr.length>0)
{
horizontalList.invalidateList();
for(var i:int=0; i < arr.length;i++ )
{
var cu:UserInfo = arr[i] as UserInfo;
cu.userName = "xiaoli";
cu.age = 11;
}
}
}
  • 打赏
  • 举报
回复
发帖
Flex

4328

社区成员

多媒体/设计 Flex
社区管理员
  • Flex
加入社区
帖子事件
创建了帖子
2011-03-09 02:03
社区公告
暂无公告