我对 JavaScript 相当陌生。我用它来Jasonify一个数组:
<script>
var numobjects = jQuery.parseJSON('{{result|jsonify}}');
</script>
结果是正确的:
jQuery.parseJSON
('[
{"category": "Perfumes", "comments": [good]},
{"category": "Perfumes", "comments": [ok]},
{"category": "Perfumes", "comments": [I like it!]}
]');
我现在不知道如何使用 JavaScript 获取“评论”对象。我尝试过这样的事情: Getting JavaScript object key list
<script>
var numobjects = [jQuery.parseJSON('{{result|jsonify}}')];
var com = [];
for (var comments in numobjects) com.push(comments);
{
console.log("total " + com.length + " comments: " + comments);
}
</script>
感谢您的帮助