0

私について:
私は始めたばかりです。これを行うには簡単な方法が必要だと私は知っていますが、1週間経ってもまだ困惑しています。
内容:
非常に長い手順書に代わるアプリを作成しました。実行中のテストについて、前に示した回答をテキスト入力ボックスに入力してもらいたいと思います。
問題:
DBから正しい情報を取得できます。ただし、テキスト入力フィールドに入力できません。ボックスには次のように表示されます。[オブジェクトオブジェクト]

どんな助けでも大歓迎です。

Settings.mxmlページのサンプルコードは次のとおりです。

<?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="Settings" >
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>

    <s:Label id="DB_Name_Label" left="10" top="10" width="150" height="50" fontSize="28"
             text="DB Name" textAlign="right" verticalAlign="middle"/>
    <s:TextInput id="DB_Name_Input" left="170" top="10" width="300" height="50" fontSize="32"/>

    <s:Label id="Test_Title" left="10" top="70" width="150" height="50" fontSize="28"
             text="Test Title" textAlign="right" verticalAlign="middle"/>
    <s:TextInput id="Test_Title_Input" left="170" top="70" width="300" height="50" fontSize="32"/>

    <s:Button id="Equipment_Button" left="10" right="10" top="130" height="50"
              label="Save, then next Page" click="EquipmentButtonClick()"/>

    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import spark.events.ViewNavigatorEvent;     

            protected var sqlConnection:SQLConnection;

            public function add_info_to_DB(tableName:String, valueToBeSaved:String):void
            {
                sqlConnection = new SQLConnection();
                sqlConnection.open(File.userDirectory.resolvePath(DB_Name_Input.text+".db"));
                var add2db:SQLStatement = new SQLStatement();
                add2db.sqlConnection = sqlConnection;
                add2db.text = ("CREATE TABLE IF NOT EXISTS "+tableName+" (id INTEGER PRIMARY KEY AUTOINCREMENT, answer TEXT)");
                add2db.execute();

                add2db.text = "INSERT INTO "+tableName+" (answer) VALUES (?)";
                add2db.parameters[0] = valueToBeSaved;
                add2db.execute();
            }

            [bindable] public var testdata:Object= new Object();

            protected function EquipmentButtonClick():void
            {   
                add_info_to_DB("Test_Title",Test_Title_Input.text);         
                navigator.pushView(views.ReadfromDB, testdata);
            }
        ]]>
    </fx:Script>
</s:View>

ReadfromDB.mxmlページのコードは次のとおりです。

<?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="Reading" >
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>

    <s:Label id="DB_to_Read_Label" left="10" top="10" width="150" height="50" fontSize="28"
             text="DB to Read" textAlign="right" verticalAlign="middle"/>
    <s:TextInput id="DB_to_Read" left="170" top="10" width="300" height="50" fontSize="32"/>

    <s:Label id="Test_Title" left="10" top="70" width="150" height="50" fontSize="28"
             text="Test Title" textAlign="right" verticalAlign="middle"/>
    <s:TextInput id="Test_Title_Input" left="170" top="70" width="300" height="50" fontSize="32"/>

    <s:Button id="Populate_Button" left="10" right="10" top="130" height="50" label="Populate"
              click="PopulateButtonClick()"/>

    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import spark.events.ViewNavigatorEvent;     

            protected var sqlConnection:SQLConnection;
            public var valueToBeRead:String;

            public function get_DB_info(tableName:String):void
            {   
                sqlConnection = new SQLConnection();
                sqlConnection.open(File.userDirectory.resolvePath(DB_to_Read.text+".db"));
                var add2db:SQLStatement = new SQLStatement();
                add2db.sqlConnection = sqlConnection;
                add2db.text = ("SELECT answer FROM "+tableName+" ORDER BY id DESC LIMIT 1");
                add2db.execute();
                valueToBeRead = add2db.getResult().data.toString();//.valueOf();//.toString();
            }

            protected function PopulateButtonClick():void
            {   
                get_DB_info("Test_Title");  
                Test_Title_Input.text = valueToBeRead;
            }
        ]]>
    </fx:Script>
</s:View>
4

1 に答える 1

1

呼び出すときadd2db.getResult()、returnオブジェクトはSQLResultです。データプロパティに関する情報は非常に役立ちます。これは、データプロパティが結果ArrayObjects含むものであることを示しています。

あなたの場合、SQLクエリは正確に1つのデータベース行を返し、その行には1つの列しか含まれていないようです。answer

したがって、次のようにテキスト入力を入力できるはずです。

var firstRow:Object = add2db.getResult().data[0];
valueToBeRead = firstRow["answer"];
// or, instead of storing it in a variable, just assign it to the text input right away
Test_Title_Input.text = firstRow["answer"];
于 2012-04-22T06:10:26.727 に答える