2012-03-02 74 views
1

首先,我是使用Flex的新手,但我已经将这个应用程序与在线教程和信息的帮助结合在一起。基本上我的应用程序就像名称,地址等等的目录,但我还有“周”和“日”的其他字段。我想要做的是列出只显示星期一至星期一的名称。以下是我用来帮助您理解我所要做的一些代码。我感谢任何帮助!Flex 4.6移动sqlite特定数据

<s:List dataProvider="{AddDoctorDatabase.doctors()}" labelField="name" change="onDoctorSelected(event)" 
     left="0" right="0" top="0" bottom="0"> 
</s:List> 


public static function doctors():ArrayCollection 
    { 
     var doctorList:ArrayCollection = new ArrayCollection(); 

     var sql:String = "SELECT id, week, day, name, address, city, state, zip, phone FROM doctors"; 
     var stmt:SQLStatement = new SQLStatement(); 
     stmt.sqlConnection = sqlConnection; 
     stmt.text = sql; 
     stmt.execute(); 
     var sqlResult:SQLResult = stmt.getResult(); 
     if (sqlResult) { 
      var result:Array = sqlResult.data; 
      if (result) { 
       for (var index:Number = 0; index < result.length; index++) { 
        doctorList.addItem(processRow(result[index])); 
       } 
      } 
     } 
     return doctorList; 
    } 

添加医生

<s:SpinnerListContainer> 
     <s:SpinnerList id="weekField" width="100" height="75" labelField="week"> 
      <s:ArrayList> 
       <fx:Object week="Week 1"/> 
       <fx:Object week="Week 2"/> 
      </s:ArrayList>       
     </s:SpinnerList> 
    </s:SpinnerListContainer> 

    <s:Label text="Select a day:"/> 
    <s:SpinnerListContainer> 
     <s:SpinnerList id="dayField" width="100" height="150" labelField="day"> 
      <s:ArrayList> 
       <fx:Object day="Monday"/> 
       <fx:Object day="Tuesday"/> 
       <fx:Object day="Wednesday"/> 
       <fx:Object day="Thursday"/> 
       <fx:Object day="Friday"/> 
      </s:ArrayList>       
     </s:SpinnerList> 
    </s:SpinnerListContainer> 

protected function onSave():void { 
      var newDoctor:AddDoctor = new AddDoctor(); 
      newDoctor.week = weekField.selectedItem; 
      newDoctor.day = dayField.selectedItem; 
      newDoctor.name = nameField.text; 
      newDoctor.address = addressField.text; 
      newDoctor.city = cityField.text; 
      newDoctor.state = stateField.text; 
      newDoctor.zip = zipField.text; 
      newDoctor.phone = phoneField.text; 
      AddDoctorDatabase.addDoctor(newDoctor); 
+0

我不知道,我明白你的问题,如果我做你需要的是在S中的labelFunction:列表,而不是使用的labelField,这样你就可以合相,你要为显示领域的功能应该带一个item:Object参数,它将被输入为你的数据提供者的数据元素之一,它应该返回a:String类似... function myLabelFunction(item:Object):String,在函数中你会做类似return item.weekValue +“ - ”+ item.dayValue – shaunhusain 2012-03-02 19:27:31

+0

基本上sqlite数据库有id,week,name,地址,城市,州,邮编,电话。我希望能够填充显示特定星期和特定日期的名称的列表。例如,显示星期二的第1周的所有名称。 – Nik 2012-03-03 17:38:51

+0

好吧2个问题,我想我可以给你一个答案。 1什么是processRow? 2你是否有其他的输入框,你可以选择星期和星期几,并且你希望它给你只有那一周和那天的行数? – shaunhusain 2012-03-05 05:49:48

回答

0

这应该工作,我想
我不是专家,但我认为比这能帮助你!

<fx:Script> 
    <![CDATA[ 
    //Add this 
    [Bindable] 
    public var dList:ArrayCollection; 

private function searchDoctorsClicked(event:MouseEvent):void 
{ 
    dList = getDoctorForWeekAndDay(weekField.selectedItem, dayField.selectedItem); 
} 

private function creationComplete_handler(event:Event):void 
{ 
    dList = getAllDoctors(); 
} 

public function getAllDoctors():ArrayCollection 
{ 
    var doctorList:ArrayCollection = new ArrayCollection(); 

    var sql:String = "SELECT id, week, day, name, address, city, state, zip, phone FROM doctors"; 
    var stmt:SQLStatement = new SQLStatement(); 
    stmt.sqlConnection = sqlConnection; 
    stmt.text = sql; 
    stmt.execute(); 
    var result:Array = stmt.getResult().data; 
    if (result) 
    { 
     for (var index:Number = 0; index < result.length; index++) 
     { 
     //doctorList.addItem(processRow(result[index])); 
     doctorList.addItem({result[index].week, result[index].day, result[index].name}); 
     } 
     return doctorList; 
    } 
    else 
    { 
    return null; 
    } 
} 


//Call this one when they select a week and day and hit a button, or just 
//on change of those options pass through the value/selectedItem from each list 
public function getDoctorForWeekAndDay(chosenWeek:String, chosenDay:String):ArrayCollection 
{ 
    var doctorList:ArrayCollection = new ArrayCollection(); 

    var sql:String = "SELECT id, week, day, name, address, city, state, zip, phone FROM doctors WHERE week='"+chosenWeek+"' AND day='"+chosenDay+"'"; 
    var stmt:SQLStatement = new SQLStatement(); 
    stmt.sqlConnection = sqlConnection; 
    stmt.text = sql; 
    stmt.execute(); 
    var result:Array = stmt.getResult().data; 
    if (result) 
    { 
     for (var index:Number = 0; index < result.length; index++) 
     { 
     //doctorList.addItem(processRow(result[index])); 
     doctorList.addItem({result[index].week, result[index].day, result[index].name}); 
     } 
     return doctorList; 
    } 
    else 
    { 
    return null; 
    } 
} 
]]> 
</fx:Script> 

<s:List dataProvider="{dList}" change="onDoctorSelected(event)" left="0" right="0" top="0" bottom="0"> 
    <s:IconItemRenderer label="{week} - { day }" messageField="name" /> 
</s:List> 
+0

我认为这会工作,但我得到一个错误1137:不正确的参数数量,预计不会超过1为以下行doctorList.addItem(result [index] .week,result [index] .day,result [index ]。名称); – Nik 2012-03-03 02:04:33

+0

当我切换到列表视图的设计模式时,我也遇到了一个错误,我从未见过这个,但我看不到任何设计。它只是说“如果该属性也被明确设置为标记或属性,则无法为默认属性数据提供者指定值”。 – Nik 2012-03-03 02:28:41

+0

您必须在代码的其他部分初始化dList变量,请尝试在另一个函数中执行此'dList = doctors()',而不是在dataProvider(dataProvider =“{dList}”) – Superlandero 2012-03-05 19:01:38

1

假设这是由Christophe Coenraetsemployee directory sample启发,你必须创建一个医生级别,并设置在processRow功能的公共变量,在ArrayCollection中加入新创建的医生对象之前,您检索到的数据:

<fx:Script> 
    <![CDATA[ 
    //Add this 
    [Bindable] 
    public var dList:ArrayCollection; 



private function searchDoctorsClicked(event:MouseEvent):void 
{ 
    dList = getDoctorForWeekAndDay(weekField.selectedItem, dayField.selectedItem); 
} 

private function creationComplete_handler(event:Event):void 
{ 
    dList = getAllDoctors(); 
} 

public function getAllDoctors():ArrayCollection 
{ 
    var doctorList:ArrayCollection = new ArrayCollection(); 

    var sql:String = "SELECT id, week, day, name, address, city, state, zip, phone FROM doctors"; 
    var stmt:SQLStatement = new SQLStatement(); 
    stmt.sqlConnection = sqlConnection; 
    stmt.text = sql; 
    stmt.execute(); 
    var result:Array = stmt.getResult().data; 
    if (result) 
    { 
     for (var index:Number = 0; index < result.length; index++) 
     { 
     //doctorList.addItem(processRow(result[index])); 
     doctorList.addItem({result[index].week, result[index].day, result[index].name}); 
     } 
     return doctorList; 
    } 
    else 
    { 
    return null; 
    } 
} 
public function processRow(o:Object):Doctor 
{ 
    var d:Doctor = new Doctor(); 
    d.Name = o.name; 
    d.week = o.week; 
    d.day = o.day; 

    return d; 
} 
public class Doctor() 
{ 
    public function Doctor(){} 
    public var name:String; 
    public var week:String; 
    public var day:int; 
} 

//Call this one when they select a week and day and hit a button, or just 
//on change of those options pass through the value/selectedItem from each list 
public function getDoctorForWeekAndDay(chosenWeek:String, chosenDay:String):ArrayCollection 
{ 
    var doctorList:ArrayCollection = new ArrayCollection(); 

    var sql:String = "SELECT id, week, day, name, address, city, state, zip, phone FROM doctors WHERE week='"+chosenWeek+"' AND day='"+chosenDay+"'"; 
    var stmt:SQLStatement = new SQLStatement(); 
    stmt.sqlConnection = sqlConnection; 
    stmt.text = sql; 
    stmt.execute(); 
    var result:Array = stmt.getResult().data; 
    if (result) 
    { 
     for (var index:Number = 0; index < result.length; index++) 
     { 
     doctorList.addItem(processRow(result[index])); 
     } 
     return doctorList; 
    } 
    else 
    { 
    return null; 
    } 
} 
]]> 
</fx:Script> 

<s:List dataProvider="{dList}" change="onDoctorSelected(event)" left="0" right="0" top="0" bottom="0"> 
    <s:IconItemRenderer label="{week} - { day }" messageField="name" /> 
</s:List>