lightning custom modal怎么把值传给所在的容器component

在lightning 里如果想弹出一个custom modal, 典型的三板斧做法如下:

$A.createComponent(
            "c:xxxxxModalContentComponent", 
            {
                'someAttribute' : somevalue,
                ...
            },
            function(content, status) {
                if (status === "SUCCESS") {
                    component.find('overlayLib').showCustomModal({
                        header: 'Some header text',
                        body: content, // the created component content
                        showCloseButton: true,
                        cssClass: "mymodal",
                        closeCallback: function() {
                            // some of you logic
                        }
                    });
                }
            }
        );

如果这个modal是让用户输入内容,返回给所在的外层component. 之前我的做法是,modal那个component发一个event, 把要传递的信息广播出来。然后外层容器监听event 获得信息。关于component之间的信息传递,好像文档里就是这样说的,用event. 

但是,仅仅为了传递这点小玩意,还得定义event 还有触发event,监听event,真是好麻烦啊。

这两天学了一招,不用event简便好多!

$A.createComponent(
    "c:xxxxModalContentComponent", 
    {
        'someAttributeOfModalComponent' : component.getReference('v.someAttributeOfParentComponent'),
        ...
    },

这样就之间把两个component的attribute连在一起了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值