Flex/DataGrid:更新每一行dataProvider发生变化

发布于 2024-08-27 02:55:52 字数 4070 浏览 7 评论 0原文

在 DataGrid 中,当我对 dataProvider 进行更新时,如何强制调用可见行上所有 itemRenderer 的 data() 。

我在下面按 doSomething 后网格没有更新。如果我有一个大列表,则更新是在向下滚动然后再次向上滚动时完成的,或者在 TreeGrid 的情况下,我打开/关闭一个节点。

<?xml version="1.0" ?>
<mx:VBox
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:flexlib="http://code.google.com/p/flexlib/"
initialize="_initialize()">

<mx:Script>
<![CDATA[

    import mx.events.CollectionEvent;

    import mx.controls.Alert;
    import Icons;

    [Bindable]
    private var dataProvider0:XML;

    private function _initialize():void
    {
        dataProvider0 = <node>
                <node label="A" option="1">
                    <node label="C" option="1"/>
                    <node label="D" option="1"/>
                </node>
                <node label="B" option="1">
                    <node label="E" option="1"/>
                    <node label="F" option="1"/>
                </node>
            </node>;

    }

    private function doSomething():void
    {

        dataProvider0.node[0].@option = 0;
        dataProvider0.node[0].node[0].@option = 0;


    }


]]>
</mx:Script>

<flexlib:TreeGrid
    id="treeGrid1"
    width="500"
    height="300"
    showRoot="false"
    verticalTrunks="none"
    paddingLeft="0"
    disclosureClosedIcon="{Icons.folderClosed}"
    disclosureOpenIcon="{Icons.folderOpen}"
    dataProvider="{dataProvider0}">

    <flexlib:columns>
        <flexlib:TreeGridColumn dataField="@label" headerText="Section"/>
        <mx:DataGridColumn dataField="@option" headerText="Option" width="50">
            <mx:itemRenderer>
                 <mx:Component>

                    <mx:Box xmlns:mx="http://www.adobe.com/2006/mxml" paddingBottom="0" paddingLeft="0" paddingRight="0" paddingTop="0" verticalAlign="middle" horizontalAlign="center" width="100%" height="100%">

                        <mx:Script>
                        <![CDATA[

                            [Bindable]
                            override public function set data(value:Object):void
                            {
                                super.data = value;
                                chkMain.selected = value.@option == "1";
                            }

                        ]]>
                        </mx:Script>

                        <mx:CheckBox id="chkMain"/>

                    </mx:Box>

                </mx:Component>
            </mx:itemRenderer>
        </mx:DataGridColumn>
    </flexlib:columns>

</flexlib:TreeGrid>

<mx:DataGrid
    id="dataGrid1"
    width="500"
    height="300"
    dataProvider="{dataProvider0.node}">

    <mx:columns>
        <mx:DataGridColumn dataField="@label" headerText="Section"/>
        <mx:DataGridColumn dataField="@option" headerText="Option" width="50">
            <mx:itemRenderer>
                 <mx:Component>

                    <mx:Box xmlns:mx="http://www.adobe.com/2006/mxml" paddingBottom="0" paddingLeft="0" paddingRight="0" paddingTop="0" verticalAlign="middle" horizontalAlign="center" width="100%" height="100%">

                        <mx:Script>
                        <![CDATA[

                            [Bindable]
                            override public function set data(value:Object):void
                            {
                                super.data = value;
                                chkMain.selected = value.@option == "1";
                            }

                        ]]>
                        </mx:Script>

                        <mx:CheckBox id="chkMain"/>

                    </mx:Box>

                </mx:Component>
            </mx:itemRenderer>
        </mx:DataGridColumn>
    </mx:columns>

</mx:DataGrid>

<mx:Button label="Do" click="doSomething()"/>

</mx:VBox>

In a DataGrid, how can I force data() of all itemRenderers on visible rows to be called when I've made an update to the dataProvider.

I'n the following the Grid isn't updated after pressing doSomething. If I have a large list the update is done when scrolling down and then back up again, or in the case of the TreeGrid i open/close a node.

<?xml version="1.0" ?>
<mx:VBox
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:flexlib="http://code.google.com/p/flexlib/"
initialize="_initialize()">

<mx:Script>
<![CDATA[

    import mx.events.CollectionEvent;

    import mx.controls.Alert;
    import Icons;

    [Bindable]
    private var dataProvider0:XML;

    private function _initialize():void
    {
        dataProvider0 = <node>
                <node label="A" option="1">
                    <node label="C" option="1"/>
                    <node label="D" option="1"/>
                </node>
                <node label="B" option="1">
                    <node label="E" option="1"/>
                    <node label="F" option="1"/>
                </node>
            </node>;

    }

    private function doSomething():void
    {

        dataProvider0.node[0].@option = 0;
        dataProvider0.node[0].node[0].@option = 0;


    }


]]>
</mx:Script>

<flexlib:TreeGrid
    id="treeGrid1"
    width="500"
    height="300"
    showRoot="false"
    verticalTrunks="none"
    paddingLeft="0"
    disclosureClosedIcon="{Icons.folderClosed}"
    disclosureOpenIcon="{Icons.folderOpen}"
    dataProvider="{dataProvider0}">

    <flexlib:columns>
        <flexlib:TreeGridColumn dataField="@label" headerText="Section"/>
        <mx:DataGridColumn dataField="@option" headerText="Option" width="50">
            <mx:itemRenderer>
                 <mx:Component>

                    <mx:Box xmlns:mx="http://www.adobe.com/2006/mxml" paddingBottom="0" paddingLeft="0" paddingRight="0" paddingTop="0" verticalAlign="middle" horizontalAlign="center" width="100%" height="100%">

                        <mx:Script>
                        <![CDATA[

                            [Bindable]
                            override public function set data(value:Object):void
                            {
                                super.data = value;
                                chkMain.selected = value.@option == "1";
                            }

                        ]]>
                        </mx:Script>

                        <mx:CheckBox id="chkMain"/>

                    </mx:Box>

                </mx:Component>
            </mx:itemRenderer>
        </mx:DataGridColumn>
    </flexlib:columns>

</flexlib:TreeGrid>

<mx:DataGrid
    id="dataGrid1"
    width="500"
    height="300"
    dataProvider="{dataProvider0.node}">

    <mx:columns>
        <mx:DataGridColumn dataField="@label" headerText="Section"/>
        <mx:DataGridColumn dataField="@option" headerText="Option" width="50">
            <mx:itemRenderer>
                 <mx:Component>

                    <mx:Box xmlns:mx="http://www.adobe.com/2006/mxml" paddingBottom="0" paddingLeft="0" paddingRight="0" paddingTop="0" verticalAlign="middle" horizontalAlign="center" width="100%" height="100%">

                        <mx:Script>
                        <![CDATA[

                            [Bindable]
                            override public function set data(value:Object):void
                            {
                                super.data = value;
                                chkMain.selected = value.@option == "1";
                            }

                        ]]>
                        </mx:Script>

                        <mx:CheckBox id="chkMain"/>

                    </mx:Box>

                </mx:Component>
            </mx:itemRenderer>
        </mx:DataGridColumn>
    </mx:columns>

</mx:DataGrid>

<mx:Button label="Do" click="doSomething()"/>

</mx:VBox>

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

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

发布评论

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

评论(2

浮光之海 2024-09-03 02:55:52

你尝试过吗

private function doSomething():void
{

    dataProvider0.node[0].@option = 0;
    dataProvider0.node[0].node[0].@option = 0;

    // force a redraw at earliest opportunity
    treeGrid1.invalidateDisplayList(); 

}

Have you tried

private function doSomething():void
{

    dataProvider0.node[0].@option = 0;
    dataProvider0.node[0].node[0].@option = 0;

    // force a redraw at earliest opportunity
    treeGrid1.invalidateDisplayList(); 

}
も让我眼熟你 2024-09-03 02:55:52

试试这个:

private function doSomething():void
{
    dataProvider0.node[0].@option = 0;
    dataProvider0.node[0].node[0].@option = 0;

    treeGrid1.dataProvider.refresh();
    dataGrid1.dataProvider.refresh();
}

Try this:

private function doSomething():void
{
    dataProvider0.node[0].@option = 0;
    dataProvider0.node[0].node[0].@option = 0;

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