绑定数据网格中的数据

发布于 2024-11-15 11:57:23 字数 1707 浏览 4 评论 0原文

我有一个由两个数据网格和一个按钮组成的表单。 Datagrid 1“myStaticDataGrid”具有我添加的值供用户选择。我希望按钮的单击事件将 myStaticDataGrid 的当前选择发送到第二个数据网格“myDataGrid”。如果我使用文本框和数据网格,我就能够完成此任务,但我无法找到正确的语法来从 myStaticDataGrid 获取选择数据。

这是我使用两种数据网格方法的尝试:

<s:Form id="myForm">
//The values from this grid are determined once the button is clicked.
  <s:FormItem id="myDataGrid">
    <s:DataGrid id="bdgFormData">
      <s:typicalItem>
        <s:DataItem formData="Description" xmlData="Value"/>
      </s:typicalItem>
      <s:ArrayCollection id="values"> </s:ArrayCollection>
    </s:DataGrid>
  </s:FormItem>


//The values from this grid are determined at runtime.
<s:FormItem id="myStaticDataGrid">
    <s:DataGrid id="userSelects">
        <s:typicalItem>
            <s:DataItem selects="Typical Item" codes="0000"/>
        </s:typicalItem>

        <s:ArrayCollection id="selects">
            <s:DataItem selects="Y" codes="1"/>
            <s:DataItem selects="N" codes="0"/>
        </s:ArrayCollection>
    </s:DataGrid>
</s:FormItem>

<s:FormItem label="Add Selects">
    <s:Button label="Go" click="addData(event)"/>
</s:FormItem>

我的 AS 事件发送数据:

protected function addData(event:MouseEvent):void
{

  //Put selected data at the top of the grid.
  items.addItemAt(lstFormData.typicalItem,0)

}

我的问题是在哪里绑定网格数据?

这就是我将文本框数据发送到数据网格的方式:

<s:FormItem label="myDataUtil">
  <s:Label text="Value"/>
  <s:TextInput text="@{lstFormData.typicalItem.formData}"/>
</s:FormItem>

I have a form that consists of two data grids and a button. Datagrid 1, "myStaticDataGrid", has values I have added for the user to select from. I want the button's click event to send the current selection of myStaticDataGrid to the second datagrid, "myDataGrid". I have been able to accomplish this if I use a text box and a datagrid but I am having trouble finding the right syntax to grab the selection data from myStaticDataGrid.

This is my attempt using the two datagrid approach:

<s:Form id="myForm">
//The values from this grid are determined once the button is clicked.
  <s:FormItem id="myDataGrid">
    <s:DataGrid id="bdgFormData">
      <s:typicalItem>
        <s:DataItem formData="Description" xmlData="Value"/>
      </s:typicalItem>
      <s:ArrayCollection id="values"> </s:ArrayCollection>
    </s:DataGrid>
  </s:FormItem>


//The values from this grid are determined at runtime.
<s:FormItem id="myStaticDataGrid">
    <s:DataGrid id="userSelects">
        <s:typicalItem>
            <s:DataItem selects="Typical Item" codes="0000"/>
        </s:typicalItem>

        <s:ArrayCollection id="selects">
            <s:DataItem selects="Y" codes="1"/>
            <s:DataItem selects="N" codes="0"/>
        </s:ArrayCollection>
    </s:DataGrid>
</s:FormItem>

<s:FormItem label="Add Selects">
    <s:Button label="Go" click="addData(event)"/>
</s:FormItem>

My AS event to send the data:

protected function addData(event:MouseEvent):void
{

  //Put selected data at the top of the grid.
  items.addItemAt(lstFormData.typicalItem,0)

}

My question is where do I bind the grid data?

This is how I send the textbox data to a the datagrid:

<s:FormItem label="myDataUtil">
  <s:Label text="Value"/>
  <s:TextInput text="@{lstFormData.typicalItem.formData}"/>
</s:FormItem>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凌乱心跳 2024-11-22 11:57:23

我为你准备了这个,不幸的是我这里只有 flex 3,所以你必须根据你需要的任何内容进行转换,但你应该了解它是如何工作的。

<?xml version="1.0" encoding="utf-8"?>
  <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
  <mx:Script>
  <![CDATA[
  import mx.collections.ArrayCollection;
  [Bindable]
  public var originalData:ArrayCollection

  [Bindable]
  public var changingData:ArrayCollection;

  public function init( ):void{
    this.changingData = new ArrayCollection( )
    this.originalData = new ArrayCollection( )
    for( var i:int = 0;i<100;i++){
      var obj:Object = new Object( )
      obj.label = 'slot '+ i;
      obj.value = 's'+i;
      originalData.addItem( obj );
    }
  }

  public function onSelect( e:Event ):void{
    this.changingData.addItem(( e.currentTarget as DataGrid).selectedItem )
  }

  ]]> 
  </mx:Script>

<mx:DataGrid id="myStaticDataGrid" dataProvider="{originalData}"  click="onSelect(event)"/>
<mx:DataGrid id="bdgFormData" dataProvider="{changingData}" x="240" y="0"/>

</mx:Application>

这是一个没有绑定数据的示例

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

            public function onSelect( e:Event ):void{
                var targetProvider:ArrayCollection = ( bdgFormData.dataProvider as ArrayCollection )
                if( !targetProvider ){
                    targetProvider = new ArrayCollection()
                }
                targetProvider.addItem(( e.currentTarget as DataGrid).selectedItem )
                bdgFormData.dataProvider = targetProvider
            }

    ]]> 
</mx:Script>

<mx:DataGrid id="myStaticDataGrid" click="onSelect(event)" >
    <mx:dataProvider>
        <mx:ArrayCollection >
            <mx:Object label="AIR" />
            <mx:Object label="ColdFusion" />
            <mx:Object label="Dreamweaver" />
            <mx:Object label="Flash" />
            <mx:Object label="Flex" />
            <mx:Object label="Photoshop" />
        </mx:ArrayCollection>
    </mx:dataProvider>
</mx:DataGrid>
<mx:DataGrid id="bdgFormData" x="240" y="0"/>

I whipped this up for you unfortunately I only have flex 3 here so you will have to make conversions for whatever you need but you should get the idea of how it works.

<?xml version="1.0" encoding="utf-8"?>
  <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
  <mx:Script>
  <![CDATA[
  import mx.collections.ArrayCollection;
  [Bindable]
  public var originalData:ArrayCollection

  [Bindable]
  public var changingData:ArrayCollection;

  public function init( ):void{
    this.changingData = new ArrayCollection( )
    this.originalData = new ArrayCollection( )
    for( var i:int = 0;i<100;i++){
      var obj:Object = new Object( )
      obj.label = 'slot '+ i;
      obj.value = 's'+i;
      originalData.addItem( obj );
    }
  }

  public function onSelect( e:Event ):void{
    this.changingData.addItem(( e.currentTarget as DataGrid).selectedItem )
  }

  ]]> 
  </mx:Script>

<mx:DataGrid id="myStaticDataGrid" dataProvider="{originalData}"  click="onSelect(event)"/>
<mx:DataGrid id="bdgFormData" dataProvider="{changingData}" x="240" y="0"/>

</mx:Application>

Here is an example without binding data

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

            public function onSelect( e:Event ):void{
                var targetProvider:ArrayCollection = ( bdgFormData.dataProvider as ArrayCollection )
                if( !targetProvider ){
                    targetProvider = new ArrayCollection()
                }
                targetProvider.addItem(( e.currentTarget as DataGrid).selectedItem )
                bdgFormData.dataProvider = targetProvider
            }

    ]]> 
</mx:Script>

<mx:DataGrid id="myStaticDataGrid" click="onSelect(event)" >
    <mx:dataProvider>
        <mx:ArrayCollection >
            <mx:Object label="AIR" />
            <mx:Object label="ColdFusion" />
            <mx:Object label="Dreamweaver" />
            <mx:Object label="Flash" />
            <mx:Object label="Flex" />
            <mx:Object label="Photoshop" />
        </mx:ArrayCollection>
    </mx:dataProvider>
</mx:DataGrid>
<mx:DataGrid id="bdgFormData" x="240" y="0"/>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文