项目

tiptap forEach 命令

遍历一个项目数组。

参数

items: any[]

一个项目数组。

fn: (item: any, props: CommandProps & { index: number }) => boolean

一个可以对项目执行任何操作的函数。

使用示例

const items = ["foo", "bar", "baz"];

editor.commands.forEach(items, (item, { commands }) => {
  commands.insertContent(item);
});

在这个例子中,forEach 会依次处理数组中的每个元素 items ,并将每个元素传递给 fn 函数。函数可以访问当前项目的值( item )以及命令上下文对象( props ),其中包含 index 属性,表示该项目在数组中的位置。fn 函数返回 boolean 值,但这通常不是必需的,因为 forEach 默认会继续处理下一个项目。在这里,我们简单地将项目插入到编辑器内容中。

在本文档中