【发布时间】:2013-08-24 07:30:49
【问题描述】:
我正在尝试从包含一些 bbcode 的给定字符串在 javascript 中创建一个对象。
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
};
然后我会将对象发送到一个渲染函数,该函数将从它递归地创建画布文本。但我就是想不通,如何形成这个对象。
【问题讨论】:
标签: javascript object bbcode nested