2011-03-30 29 views
1

Im正在製作人物搜索應用程序。我以字符串的形式得到結果(每行代表一個人)。我想在列表中顯示這些文本行,我該怎麼做?顯示字符串的UI列表(Adobe Flex/Actionscript)

<?xml version="1.0" encoding="utf-8"?> 
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" title="PersonSearchResults"> 
<fx:Script> 
    <![CDATA[ 
     import model.PersonSummary; 
     import mx.collections.ArrayCollection; 

     public var listOfPeople:Array; 

     public function populate():void{ 
      trace("Populating"); 
      listOfPeople = String(data).split("\n"); 
     } 

    ]]> 
</fx:Script> 
<fx:Declarations> 
    <!-- Place non-visual elements (e.g., services, value objects) here --> 
</fx:Declarations> 
<s:List id="results"> 
    <s:ArrayList source="{listOfPeople}"/> 
</s:List> 

我遇到的問題是,listOfPeople陣列填充後的名單已經顯示在屏幕上......我該如何解決這個問題?

感謝 菲爾

回答

3

你不能用一個數組做綁定。改用ArrayCollection。

 [Bindable] 
     public var listOfPeople:ArrayCollection; 

     public function populate():void{ 
      listOfPeople = new ArrayCollection(String(data).split("\n")); 
     } 

    ]]> 
</fx:Script> 
<fx:Declarations> 
    <!-- Place non-visual elements (e.g., services, value objects) here --> 
</fx:Declarations> 
<s:List id="results" dataProvider="{listOfPeople}" /> 
+0

頂標先生.. – 2011-03-30 11:53:49