0
我想从包含一些bbcode的给定字符串在JavaScript中创建一个对象。从解析的bb代码创建一个嵌套对象
var bbStr = 'Text with [url=http://somelink]links and [i]nested bb code[/i][/url].';
我需要递归通过对象迭代和改造上面的字符串弄成这个样子:
var result = {
children : [
{
text : 'Text with ',
type : 'text'
},
{
children: [
{
text : 'links and ',
type : 'text'
},
{
text : 'nested bb code',
type : 'italic'
}
],
text : null,
type : 'url',
url : 'http://somelink'
},
{
text : '.',
type : 'text'
}
],
type : null,
text : null
};
然后我会的对象发送到这将递归从中创建画布文本渲染功能。但我无法理解我的头,如何形成这个对象。
这工作像一个魅力,看起来很优雅。我自己的方法真的很臃肿,最终甚至没有工作。所以,非常感谢你! – Patrick