如何访问Flex 3 ViewStack中的其他面板?
我有一个带有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定这是否是您想要的,但您可以执行以下操作:
为了使其正常工作,您还必须向视图堆栈添加创建策略。
这样,所有面板都将在创建视图堆栈时创建(默认情况下,仅在需要时才创建面板)。这可确保您在面板可见之前引用
detailsPanel
、itemTitle
、itemSummary
等。I'm not sure if this is what you want, but you can do something like this:
In order for this to work you will also have to add a creation policy to the viewstack.
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.对我来说,最好的方法是使用数据绑定。只需引入附加字段
并在 showDetails 方法中填充详细信息即可。如果需要异步获取详细信息数据(例如,从服务器),您可以重置当前详细信息值,直到收到数据:
然后用服务器数据填充它。
最终的更改在详细数据网格中:
希望它有所帮助。
As for me the best way is to use data binding. Just introduce additional field
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:
And then populate it with server data.
The final changes are in details data grid:
Hope it helps.
这里的代码将解释“stackview”简单的例子。使用这个可以同样调用面板。
Here this code will explain 'stackview' simple example. Using this can call panel as same.