如何访问Flex 3 ViewStack中的其他面板?

发布于 2024-10-27 21:48:54 字数 1499 浏览 1 评论 0原文

我有一个带有 2 个面板的 ViewStack:

<mx:ViewStack id="viewstack1" height="243">
<mx:Panel id="gridPanel">
    <mx:DataGrid id="grid" right="10" left="10" top="10" bottom="10" width="300" height="150" itemClick="showDetails(event)">
        <mx:columns>
                <mx:DataGridColumn headerText="ID" dataField="Id"/>
                <mx:DataGridColumn headerText="Summary" dataField="Summary"/>
            </mx:columns>
        </mx:DataGrid>
    </mx:Panel>
    <mx:Panel id="detailsPanel">
        <mx:HBox width="100%" height="100%">
            <mx:VBox height="100%" width="228" id="detailsVbox">
                <mx:Label text="Label" id="itemTitle"/>
                <mx:Text text="Text" id="itemSummary"/>
                <mx:DataGrid height="97">
                    <mx:columns>
                        <mx:DataGridColumn headerText="Property" dataField="col1"/>
                        <mx:DataGridColumn headerText="Value" dataField="col2"/>
                    </mx:columns>
                </mx:DataGrid>
            </mx:VBox>
            <mx:Image source="images/BackButton.png" width="50" height="50" click="viewstack1.selectedChild = gridPanel"/>

        </mx:HBox>
</mx:Panel>     
</mx:ViewStack>

我想让用户单击第一个面板中的网格项,然后将数据加载到第二个面板中的面板中。我可以在 itemClicked 处理程序中获取单击项目的索引值,但是如何访问详细信息面板以根据网格中的行信息设置值?

I have a ViewStack with 2 panels:

<mx:ViewStack id="viewstack1" height="243">
<mx:Panel id="gridPanel">
    <mx:DataGrid id="grid" right="10" left="10" top="10" bottom="10" width="300" height="150" itemClick="showDetails(event)">
        <mx:columns>
                <mx:DataGridColumn headerText="ID" dataField="Id"/>
                <mx:DataGridColumn headerText="Summary" dataField="Summary"/>
            </mx:columns>
        </mx:DataGrid>
    </mx:Panel>
    <mx:Panel id="detailsPanel">
        <mx:HBox width="100%" height="100%">
            <mx:VBox height="100%" width="228" id="detailsVbox">
                <mx:Label text="Label" id="itemTitle"/>
                <mx:Text text="Text" id="itemSummary"/>
                <mx:DataGrid height="97">
                    <mx:columns>
                        <mx:DataGridColumn headerText="Property" dataField="col1"/>
                        <mx:DataGridColumn headerText="Value" dataField="col2"/>
                    </mx:columns>
                </mx:DataGrid>
            </mx:VBox>
            <mx:Image source="images/BackButton.png" width="50" height="50" click="viewstack1.selectedChild = gridPanel"/>

        </mx:HBox>
</mx:Panel>     
</mx:ViewStack>

I want to have the user click a grid item in the first panel and then load the data in a panel in the second panel. I can grab the value of the index for the clicked item in the itemClicked handler, but how do I access the detailsPanel to set the values based on the row info from the Grid?

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

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

发布评论

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

评论(3

你不是我要的菜∠ 2024-11-03 21:48:54

我不确定这是否是您想要的,但您可以执行以下操作:

private function showDetails(event:ListEvent):void {
    itemTitle.text = event.itemRenderer.data.Id;
    itemSummary.text = event.itemRenderer.data.Summary;

    //assuming that the datagrid ID from the details panel is: detailsDatagrid 
    detailsDatagrid.dataProvider = event.itemRenderer.data.Properties;

    viewstack1.selectedChild = detailsPanel;
}

为了使其正常工作,您还必须向视图堆栈添加创建策略。

<mx:ViewStack id="viewstack1" height="243" creationPolicy="all">

这样,所有面板都将在创建视图堆栈时创建(默认情况下,仅在需要时才创建面板)。这可确保您在面板可见之前引用 detailsPanelitemTitleitemSummary 等。

I'm not sure if this is what you want, but you can do something like this:

private function showDetails(event:ListEvent):void {
    itemTitle.text = event.itemRenderer.data.Id;
    itemSummary.text = event.itemRenderer.data.Summary;

    //assuming that the datagrid ID from the details panel is: detailsDatagrid 
    detailsDatagrid.dataProvider = event.itemRenderer.data.Properties;

    viewstack1.selectedChild = detailsPanel;
}

In order for this to work you will also have to add a creation policy to the viewstack.

<mx:ViewStack id="viewstack1" height="243" creationPolicy="all">

This way all panels are going to be created when the viewstack is created (by default they are created only when they are needed). This ensures that you will have a reference the detailsPanel, itemTitle, itemSummary, etc... before the panel is visible.

眼藏柔 2024-11-03 21:48:54

对我来说,最好的方法是使用数据绑定。只需引入附加字段

[Bindable]
private var detailsDataProvider:ArrayCollection;

并在 showDetails 方法中填充详细信息即可。如果需要异步获取详细信息数据(例如,从服务器),您可以重置当前详细信息值,直到收到数据:

detailsDataProvider = null;

然后用服务器数据填充它。

最终的更改在详细数据网格中:

<mx:DataGrid height="97" dataProvider="{detailsDataProvider}">

希望它有所帮助。

As for me the best way is to use data binding. Just introduce additional field

[Bindable]
private var detailsDataProvider:ArrayCollection;

And fill it with details in showDetails method. If details data need to be obtained asynchronously (from server, for example) you can reset current details value until data received:

detailsDataProvider = null;

And then populate it with server data.

The final changes are in details data grid:

<mx:DataGrid height="97" dataProvider="{detailsDataProvider}">

Hope it helps.

情话已封尘 2024-11-03 21:48:54

这里的代码将解释“stackview”简单的例子。使用这个可以同样调用面板。

Here this code will explain 'stackview' simple example. Using this can call panel as same.

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