我正在使用GrapesJS模板编辑器处理一个项目,我正在try 使用两个按钮实现撤销/重复功能.当然,我创建的按钮目前没有撤销和重复操作.

请帮助我!

<div class="action">
    <a class="btn" id="undo-btn"><i class="fa fa-undo"></i></a>
    <a class="btn" id="redo-btn"><i class="fa fa-redo"></i></a>
</div>
const editor = grapesjs.init({
  // Indicate where to init the editor. You can also pass an HTMLElement
  container: '#gjs',
  // Get the content for the canvas directly from the element
  // As an alternative we could use: `components: '<h1>Hello World Component!</h1>'`,
  fromElement: true,
  // Size of the editor
  height: '300px',
  width: 'auto',
  // Disable the storage manager for the moment
  storageManager: false,
  // Avoid any default panel
  panels: { defaults: [...] },
  // ...
});
$('#undo-btn').click(function() {
    // undo action here
})
$('#redo-btn').click(function() {
    // redo action here
})

推荐答案

您可以使用以下代码:

$('#undo-btn').click(function() {
    editor.Commands.run('core:undo');
})
$('#redo-btn').click(function() {
    editor.Commands.run('core:redo');
})

Javascript相关问答推荐

如何从对象嵌套数组的第二级对象中过滤出键

使用JavaScript在ionic Web应用程序中更新.pane和.view的背景 colored颜色

单击更新页面的按钮后,页面刷新;测试/断言超时,有两个标题,但没有一个标题

了解Node.js中的EventEums和浏览器中的addEventEums之间的关系

我可以从React中的出口从主布局调用一个处理程序函数吗?

仅针对RTK查询中的未经授权的错误取消maxRetries

在拖放时阻止文件打开

无法检测卡片重叠状态的问题

Regex结果包含额外的match/group,只带一个返回

保持物品顺序的可变大小物品分配到平衡组的算法

将Node.js包发布到GitHub包-错误ENEEDAUTH

如何在 Select 文本时停止Click事件?

如何确保预订系统跨不同时区的日期时间处理一致?

为什么云存储中的文件不能公开使用?

JavaScript:如果字符串不是A或B,则

将Auth0用户对象存储在nextjs类型脚本的Reaction上下文中

在GraphQL解析器中修改上下文值

FireBase FiRestore安全规则-嵌套对象的MapDiff

我不知道如何纠正这一点.

P5JS-绘制不重叠的圆