我想在jQuery中解析嵌套的動態數組。 代碼: -在jQuery中獲取動態數組的值
new Ajax.Request(url, { // url of the controller
method: 'get',
parameters: { search: searchString }, //parameter
onComplete: function(transport) {
alert(transport.responseText);
var values = transport.responseText;
alert(values.length);
// response from the controller will get alerted.
for(var i=0;i<values.length;i++){
for (var x in values[i]){
console.log(x+"="+values[i][x]);
}
}
}
});
當我警覺陣列則表明數組是這樣的: -
Array
(
[0] => Array
(
[post_id] => 1
[title] => Womens Health
[post_content] => Lorem Ipsum is simply dummy text of the printing and typesetting industry.
[status] => 1
[created_time] => 2014-01-20 20:15:34
[update_time] => 2014-02-27 18:51:42
[identifier] => women_health
[user] => aheadWorks
[update_user] => Bod christen
[meta_keywords] => Must-have Magento Extensions, aheadWorks
[meta_description] => Must-have Magento Extensions
[comments] => 0
[tags] =>
[short_content] => <p><img src="{{skin url='images/journal.jpeg'}}" alt="" /></p>
)
[1] => Array
(
[post_id] => 2
[title] => Ladies Home Joural
[post_content] => <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry</p>
[status] => 1
[created_time] => 2014-02-17 18:02:54
[update_time] => 2014-02-27 18:49:46
[identifier] => ladies_home_joural
[user] => Bod christen
[update_user] => Bod christen
[meta_keywords] =>
[meta_description] =>
[comments] => 0
[tags] =>
[short_content] => <p><img src="{{skin url='images/journal1.jpeg'}}" alt="" /></p>
)
)
提示....使用'for each'循環。看看這個:http://stackoverflow.com/questions/9329446/for-each-in-an-array-how-to-do-that-in-javascript –
我想得到,但它返回undefined –
發佈您正在嘗試使用的代碼 –