0

与openfin一样,我们可以单独打开单独的小部件/窗口,它们如何相互通信,搜索了很多都找不到任何东西,请帮助。

4

1 回答 1

0

您可以使用从主窗口共享上下文到其所有父视图customContext

在窗口(框架)

const me = fin.Window.getCurrentSync();
me.on('options-changed', async (event) => {
    if (event.diff.customContext) {
        const myViews = await me.getCurrentViews();
        const customContext = event.diff.customContext.newVal;
        myViews.forEach(v => {
            v.updateOptions({ customContext });
        });
    }
})

在视图中(内容)

const me = fin.View.getCurrentSync();
const broadcastContext = async (customContext) => {
    const myWindow = await me.getCurrentWindow()
    await myWindow.updateOptions({ customContext })
};
const addContextListener = async (listener) => {
    await me.on('options-changed', (event) => {
        if (event.diff.customContext) {
            listener(event.diff.customContext.newVal);
        }
    });
}

参考资料 - https://cdn.openfin.co/docs/javascript/stable/tutorial-customContext.html

于 2020-04-19T10:08:45.590 回答