首页 新闻 会员 周边

使用ace_editor编辑器想要展示“对象或者数组内容”,而非文本格式,应该如何实现?

0
悬赏园豆:200 [已解决问题] 解决于 2021-03-02 15:58

项目环境:angular8
ace_editor相应配置:
// 开启代码折叠
this.editor.getSession().setUseWrapMode(true);
this.editor.setOptions({
mode: 'ace/mode/javascript',
readOnly: false,
theme: 'ace/theme/github',
newLineMode: 'unix'
});
问题描述:当编辑器的内容是“字符串格式”时,可以正常显示内容,把内容替换为“对象”或“数组”格式时,程序就会报错。
content = 'Hello World'; 成功
content = {
aa: '123',
bb: '123'
}; 报错
报错信息:
Unhandled Promise rejection: e.match is not a function ; Zone: <root> ; Task: Promise.then ; Value: TypeError: e.match is not a function

前端小白L的主页 前端小白L | 初学一级 | 园豆:22
提问于:2021-03-02 12:49
< >
分享
最佳答案
0

对象或数组需要序列化,你可以这样试试:

content = JSON.stringify({
    aa: '123',
    bb: '123'
});
收获园豆:200
baogao_pro | 小虾三级 |园豆:619 | 2021-03-02 14:08
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册