0

我是 Flex 的新手,忙于使用自定义表单将表单数据保存到 xml。我创建了表格:

形式:

<s:Panel width="875" height="677" horizontalCenter="0" title="Add New Client to Database"
             verticalCenter="0">
        <s:Label x="17" y="23" text="Title:"/>
        <s:DropDownList  x="17" y="43" requireSelection="true">
            <s:dataProvider>
                <s:ArrayList id="clientTitle" source="[Mr, Mnr, Dr]" />
            </s:dataProvider>
        </s:DropDownList>
        <s:Label x="209" y="23" text="Gender:"/>
        <s:DropDownList id="clientGender" x="209" y="43" requireSelection="true">
            <s:dataProvider>
                <s:ArrayList source="[Male, Female]" />
            </s:dataProvider>
        </s:DropDownList>
        <s:Label x="17" y="84" text="Full Names:"/>
        <s:TextInput id="clientNames" x="18" y="104" width="350"/>
        <s:Label x="18" y="142" text="Surname:"/>
        <s:TextInput id="clientSurname" x="18" y="162" width="350"/>
        <s:Label x="18" y="202" text="Age:"/>
        <s:TextInput id="clientAge" x="18" y="221" width="350"/>
        <s:Label x="18" y="261" text="Address:"/>
        <s:TextInput id="clientAddress" x="17" y="281" width="350"/>
        <s:Label x="17" y="322" text="City:"/>
        <s:TextInput id="clientCity" x="17" y="342" width="350"/>
        <s:Label x="17" y="382" text="Country:"/>
        <s:TextInput id="clientCountry" x="17" y="402" width="350"/>
        <s:Label x="18" y="443" text="Tel:"/>
        <s:TextInput id="clientTel" x="17" y="463" width="350"/>
        <s:Label x="17" y="503" text="Fax:"/>
        <s:TextInput id="clientFax" x="17" y="522" width="350"/>
        <s:Label x="17" y="560" text="Mobile:"/>
        <s:TextInput id="clientMobile" x="17" y="580" width="350"/>
        <s:Label x="492" y="23" text="Email:"/>
        <s:TextInput id="clientEmail" x="492" y="43" width="350"/>
        <s:Label x="492" y="84" text="Extras:"/>
        <s:CheckBox id="clientCode8" x="527" y="104" label="License Code 8"/>
        <s:CheckBox id="clientCode10" x="527" y="130" label="License Code 10"/>
        <s:CheckBox id="clientCode14" x="527" y="156" label="License Code 14"/>
        <s:CheckBox id="clientSingle" x="684" y="104" label="Single"/>
        <s:CheckBox id="clientMarried" x="684" y="130" label="Maried"/>
        <s:CheckBox id="clientDevorced" x="684" y="156" label="Devorced"/>
        <s:DropDownList id="clientEducation" x="492" y="222" width="350" requireSelection="true">
            <s:dataProvider>
                <s:ArrayList source="[Not Finished School, Matric, Diploma, N3, N4, N5, N6, Degree]" />
            </s:dataProvider>
        </s:DropDownList>

        <s:Label x="492" y="202" text="Education Level:"/>

        <s:DropDownList id="clientIndustry" x="492" y="282" width="350" requireSelection="true">
            <s:dataProvider>
                <s:ArrayList source="[Not Finished School, Matric, Diploma, N3, N4, N5, N6, Degree]" />
            </s:dataProvider>
        </s:DropDownList>

        <s:Label x="492" y="261" text="Industry:"/>
        <s:DropDownList id="clientQualification" x="492" y="342" width="350" requireSelection="true">
            <s:dataProvider>
                <s:ArrayList source="[Not Qualified, Fitter, Boilmaker]" />
            </s:dataProvider>
        </s:DropDownList>
        <s:Label x="492" y="322" text="Qualification:"/>
        <s:DropDownList id="clientSalary" x="492" y="402" width="350" requireSelection="true">
            <s:dataProvider>
                <s:ArrayList source="[0 - 1000, 1000 - 2000, 2000 - 3000, 3000 - 4000, 4000 - 5000, 5000 - 6000, 7000 - 8000, 8000 - 9000, 9000 - 10 000]" />
            </s:dataProvider>
        </s:DropDownList>
        <s:Label x="492" y="382" text="Salary:"/>
        <s:Label x="492" y="443" text="Current Employed:"/>
        <s:CheckBox id="clientEmployed" x="527" y="467" label="Is Employed"/>
        <s:CheckBox id="clientNotEmployed" x="684" y="467" label="Not Employed"/>
        <s:Button x="585" y="523" label="Upload CV to Database"/>
        <s:Button x="607" y="580" label="Save New Client" buttonMode="true" click="saveRecruit(event)" useHandCursor="true"/>
    </s:Panel>

这是我要保存到 xml 的脚本:

import mx.controls.Alert;
        protected function saveRecruit(event:MouseEvent):void
        {
            var file:File = File.desktopDirectory;
            file = file.resolvePath("recruit.xml");
            var myXML:XML =<recruit>
                            <title>{clientTitle.toString()}</title>
                            <gender>{clientGender.toString()}</gender>
                            <names>{clientNames.text}</names>
                            <surname>{clientSurname.text }</surname>
                            <age>{clientAge.text}</age>
                            <address>{clientAddress.text}</address>
                            <city>{clientCity.text}</city>
                            <country>{clientCountry.text}</country>
                            <tel>{clientTel.text}</tel>
                            <fax>{clientFax.text }</fax>
                            <mobile>{clientMobile.text}</mobile>
                            <email>{clientEmail.text}</email>
                            <extras>{clientCode8.toString()}</extras>
                            <education>{clientEducation.toString()}</education>
                            <industry>{clientIndustry.toString()}</industry>
                            <qualification>{clientQualification.toString()}</qualification>
                            <salary>{clientSalary.toString()}</salary>
                            <employed>{clientEmployed.toString()}</employed>
                          </recruit>;
            var fs:FileStream = new FileStream();
            fs.open(file, FileMode.APPEND);
            fs.writeUTFBytes(myXML);
            fs.close();
            Alert.show("Thank You! You have now been entered.","Thank You!");
        }

我无法将数据保存到 XML,有什么想法吗?

请帮忙!

4

1 回答 1

0

您只需使用该selectedItem属性:

var myXML:XML = 
    <recruit>
        <title>clientTitleInput.selectedItem</title>
        <gender>clientGenderInput.selectedItem</gender>
        ...
    </recruit>;

请注意,clientTitleInputandclientGenderInput是 DropDownLists 的 ID,而不是它们的 dataProviders 的 ID。

于 2012-08-19T21:00:03.183 回答