Flex 4.6移动sqlite特定数据

时间:2012-03-02 18:01:18

标签: flex sqlite mobile

首先我不熟悉使用Flex,但我已经将这个应用程序与在线教程和信息的帮助拼凑在一起。基本上我的应用程序就像一个名称,地址等目录,但我还有“周”和“日”的其他字段。我想要做的是有一个列表,只显示名称,例如第1周 - 周一。下面是我用来帮助您理解我想要做的一些代码。我感谢任何帮助!

<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);

2 个答案:

答案 0 :(得分:1)

假设这是受Christophe Coenraetsemployee directory sample的启发,你必须创建一个Doctor Class并在processRow函数中使用检索到的数据设置其公共变量,然后再添加新创建的Doctor对象在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>

答案 1 :(得分: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>