我有这个对象数组,如何使用 jQuery.each() 循环它?
Array ( [0] => stdClass Object ( [id] => 1 [parent_cat_id] => 1 [child_cat_name] => Java [status] => 1 [date] => 2016-09-11 01:26:00 ) [1] => stdClass Object ( [id] => 2 [parent_cat_id] => 1 [child_cat_name] => JavaScript [status] => 1 [date] => 2016-09-11 01:26:00 ) [2] => stdClass Object ( [id] => 3 [parent_cat_id] => 1 [child_cat_name] => HTML [status] => 1 [date] => 2016-09-11 01:26:00 ) [3] => stdClass Object ( [id] => 4 [parent_cat_id] => 1 [child_cat_name] => PHP [status] => 1 [date] => 2016-09-11 01:26:00 ) [4] => stdClass Object ( [id] => 5 [parent_cat_id] => 1 [child_cat_name] => Python [status] => 1 [date] => 2016-09-11 01:26:00 ) [5] => stdClass Object ( [id] => 6 [parent_cat_id] => 1 [child_cat_name] => Ruby [status] => 1 [date] => 2016-09-11 01:26:00 ) )
I am trying to use this -
$.each( data, function( key, value ) {
console.log( value );
});
这给了我以下错误 -
TypeError: invalid 'in' operand e
最佳答案
你的数组有奇怪的格式。请参阅此示例:
var data = [
{text: "hello"},
{text: "good bye"},
{text: "Hello again"}
]
$.each( data, function( key, value ) {
console.log( value.text );
});
关于javascript - 如何在对象数组上使用 jQuery.each() 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39497313/