我有这个代码:
try {
var _o, _l, i, _d = new Array(), _c;
_o = JSON.Parse( Request.Response );
for ( i = 0, _l = _o.length; i < _l; i++ ) {
_d[ i ] = document.createElement('div');
_c = document.getElementById('comentsContainer');
_c.removeChild( _c.firstChild );
_d[ i ].className = 'comment-user';
_c.appendChild( _d [i] );
}
}
catch ( w ) {
console.log( w );
}
问题是,这种方式更好还是我应该使用 innerHTML ?
添加:要解析的对象:
"comments" : [
{ "user" : "foo", "comment" : "foo", "date" : "foo/foo/bar", "id_comment" : "bar" },
{ /* the same as above x10 */ }
]
请注意,我想将每个数组中的每个对象解析为 DOM 元素