Contribute to this guide

指南测试助手

模型开发者工具视图开发者工具 公开的 getData()setData() 函数是有用的开发助手。

它们允许“字符串化” 模型视图 结构、选择、范围和位置,以及从字符串加载它们。它们通常在编写测试时使用。

这两个工具都设计用于原型设计、调试和测试目的。不要在生产级代码中使用它们。

例如,要查看编辑器模型,可以使用 getData() 助手

import { _getModelData } from 'ckeditor5';

// More imports.
// ...

ClassicEditor
    .create( '<p>Hello <b>world</b>!</p>' )
    .then( editor => {
        console.log( getData( editor.model ) );
        // -> '<paragraph>[]Hello <$text bold="true">world</$text>!</paragraph>'
    } );

查看 助手文档 以了解有关有用选项的更多信息。