2

我有一个块可以呈现<Modal/>. <ServerSideRender/>我使用(返回纯html)从服务器检索它。我希望能够选择其中一个标题(最好将其保存在postTitle属性中)并将其显示在块中。

attributes: {
    postTitle: {
        type: 'string'
    }
},

edit(props) {
    const { attributes } = props;
    const { postTitle } = props.attributes;

    const MyModal = withState( {
        isOpen: false,
    } )
    ( ( { isOpen, setState } ) => (
        <div>
            <Button isDefault onClick={ () => setState( { isOpen: true } ) }>Choose</Button>
            { isOpen ?
                <Modal onRequestClose={ () => setState( { isOpen: false } ) }>
                        <ServerSideRender
                            block="my-blocks/wordpress-title"
                            attributes={attributes}
                        />
                </Modal>
                : null }
        </div>
    ) );

    return ([
        <InspectorControls>
            <div>
                <strong>Choose Wordpress title:</strong>
                <MyModal/>
            </div>
        </InspectorControls>,
    ]);
},

是否有任何明智的方式从服务器检索数据,因此可以在一个块内对其进行操作?

4

0 回答 0