zoukankan      html  css  js  c++  java
  • 【转】Popup窗口访问父窗口的5种方法以及相互传值

    1.如果使用MVC框架,相信这并不是一个问题。而如果没有使用的话,可以用类似的方法设置一个单例,子窗口和父窗口通过这个单例来交互消息,如果需要解耦,请发送自定义事件。总之,只要按照MVC思路来做就可以了。 2.类似JS,在子窗口的构造函数里增加一个参数,将父窗口传参进去。MXML没有构造函数,用一个属性来保存父窗口引用也可以。这种方法在前面一篇文章中有详细描述。 3.无论是createPopUp还是addPopUp,他们都有一个返回值,得到子窗口的实例。可以对这个实例监听remove事件,并在这个事件中直接读取子窗口需要返回给父窗口的属性。(记得要将这个事件最终移除)






    弹出窗口:






    4.owner属性: owner:DisplayObjectContainer [read-write] UIComponent的owner属性默认是这个UIComponent的父组件. However, if this UIComponent object is a child component that is popped up by its parent, such as the dropdown list of a ComboBox control, the owner is the component that popped up this UIComponent object. This property is not managed by Flex, but by each component. Therefore, if you use the PopUpManger.createPopUp() or PopUpManger.addPopUp() method to pop up a child component, you should set the owner property of the child component to the component that popped it up. The default value is the value of the parent property. 我也不翻译了- -说真的我看到了感觉很囧。owner这个属性在Popup中没有用途,因此,可以在创建窗口的时候将子窗口的owner设置成父窗口(也就是当时的this),然后子窗口访问自己的owner属性即可。 父窗口代码:PopUpDemo.mxml





    弹出窗口代码:titlewindow.mxml





    5、 利用callback函数实现子窗口调用父窗口的函数 假设有父窗体P,在父窗体中弹出子窗体C,进行必要的操作
  • 相关阅读:
    深入理解递归函数的调用过程
    关于字符串和字符数组的再讨论
    返回字符串的长度
    再写静态变量的有效范围
    一道关于返回指针和返回数组名的面试题
    关于TCP/IP的三次握手和四次挥手解释
    C++面向对象的编程(二)
    关于面试宝典中的检测并修改不适合的继承
    argc和argv
    基于C的文件操作(转)
  • 原文地址:https://www.cnblogs.com/AS30/p/3113219.html
Copyright © 2011-2022 走看看