简体   繁体   English

在YML中使用HTML在js-yaml中产生[Objcet Object]

[英]Using HTML in YML yields [Objcet Object] in js-yaml

Using HTML in YML yields [Objcet Object] 在YML中使用HTML会产生[对象对象]

YML 阳明海运

context: fieldLabel: | <strong> Some Bold Text </strong> and now normal continued. It's rendering as 它呈现为

context: fieldLabel: ",[object Object], and now normal continued.↵" but I want my output should be context: fieldLabel: ",[object Object], and now normal continued.↵"但我希望输出为

context: { fieldLabel: '<strong>\\n Some Bold Text\\n</strong> and now normal continued.\\n' },

My JS Code : 我的JS代码:

My JS Code : 我的JS代码:

const tests = YAML.safeLoad(this.props.children,{json:true}); console.log("tests",...tests)

Console output : 控制台输出:

context: fieldLabel: ",[object Object], and now normal continued.↵"

It is coming as [object Object] instead of <strong>\\n Some Bold Text\\n</strong> 它以[object Object]而不是<strong>\\n Some Bold Text\\n</strong>

From the js-yaml docs : js-yaml docs

safeLoad (string [ , options ]) safeLoad(字符串[,options])

Recommended loading way. 推荐的加载方式。 Parses string as single YAML document. 将字符串解析为单个YAML文档。 Returns a JavaScript object or throws YAMLException on error. 返回一个JavaScript对象或在错误时引发YAMLException。 By default, does not support regexps, functions and undefined. 默认情况下,不支持正则表达式,函数和未定义。 This method is safe for untrusted data. 此方法对于不受信任的数据是安全的。

As you're including non-safe code (ie HTML) in your yaml, it looks like js-yaml is giving you an error instead. 当您在Yaml中包含非安全代码(即HTML)时,js-yaml似乎给了您一个错误。 You can do a non-safe load with load() instead, if your yaml is guaranteed to be safe, or you could modify the structure of your code to change what's stored in yaml and what isn't. 如果可以确保yaml是安全的,则可以使用load()进行非安全加载,或者可以修改代码结构以更改yaml中存储的内容和不存储的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM