Skip to content

怎么扩展amis现有的editor,增加自定义的功能呢? #37

@scofier

Description

@scofier

我按照你的例子来写,没办法接受外面的变量参数

我是想通过快捷键保存数据到后端的api接口上, 但是接口需要一个id参数,这个参数从外面获取,没办法传递一个变量${data}

`
interface MyProps extends RendererProps {

}

@Renderer({
type: 'code-editor'
})
class CodeEditor extends React.Component {

static contextType = ScopedContext;
 theme = "vs-light";
 editorInstance = null; // 保存编辑器实例

constructor(props, context) {
  super(props);
  const scoped = context;
  scoped.registerComponent(this);
}

onEditorReady = (editor, monaco) => {
    console.log("onEditorReady", editor);
    this.editorInstance = editor;

    monaco.editor.registerCommand("cmd1",()=>{
        if(this.editorInstance) {
            let value = this.editorInstance.getValue();
            console.log('Save command triggered',value);

            this.props.handleSaveContent(value);
        }
        
    })

    monaco.editor.addKeybindingRules([{keybinding:monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS,command:"cmd1"}]);
};

render() {
    return (
    <>
        <MonacoEditor
            height={800}
            options={this.props.options}
            theme={this.theme}
            value={this.props.value1}
            editorDidMount={this.onEditorReady}
        />
    </>
)};

};`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions