我想要做的是让用户将他的数据输入到多个文本框中,然后一旦输入数据,它就会在运行时显示在数据网格上。问题是当我运行应用程序时,我单击了按钮,但没有将输入的信息添加到数据网格中。一旦按下按钮,我的文本框也应该被清除,但再次没有任何反应。这是我的代码:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]private var dgItems:ArrayCollection;
[Bindable]public var temp:Object;
public function addItem(evt:Event):void {
//add item if the text input fields are not empty
if(name_input.text != ""&& location_input.text !="") {
//create a temporary Object
temp = myDG.selectedItem;
var temp:Object = new Object();
//add the text from the textfields to the object
temp = {name:name_input.text, location:location_input.text};
//this will add the object to the ArrayColldection (wich is binded with the DataGrid)
dgItems.addItem(temp);
//clear the input fields
name_input.text = "";
location_input.text ="";
}
}
]]>
</mx:Script>
<mx:DataGrid x="97" y="110" dataProvider="{dgItems}" id="myDG">
<mx:columns>
<mx:DataGridColumn headerText="Column 1" dataField="name:"/>
<mx:DataGridColumn headerText="Column 2" dataField="location:"/>
</mx:columns>
</mx:DataGrid>
<mx:Button x="97" y="51" label="add" click="addItem(event)"/>
<mx:TextInput x="117" y="300" id="location_input"/>
<mx:TextInput x="117" y="340" id="name_input"/>
</mx:Application>
任何帮助是极大的赞赏。