如何循环这个javascript对象

时间:2013-12-16 04:24:38

标签: javascript php jquery codeigniter

我正在使用jquery和codeigniter,表单codeigniter我在rsponse中传递一个json_encoded字符串json字符串是

"eod_data":{
"2013-12-13":[
{
"shop_code":"PC",
"first_name":"chanaka",
"rms_sell":"37",
"orm_repair":"30 ",
"total":"67",
"cash":"17",
"card":"50",
"opening_bal":"10.00 ",
"purchases":"0 ",
"final_total":"27",
"till_total":"60",
"difference":"33",
"nextday_opening_bal":"4",
"created_time":"2013-12-13",
"banking":"51"
},
{
"shop_code":"KF",
"first_name":"chanaka",
"rms_sell":"37",
"orm_repair":"30 ",
"total":"67",
"cash":"17",
"card":"50",
"opening_bal":"10.00 ",
"purchases":"0 ",
"final_total":"27",
"till_total":"60",
"difference":"33",
"nextday_opening_bal":"4",
"created_time":"2013-12-13",
"banking":"51"
}
],
"2013-12-12":[
{
"shop_code":"PC",
"first_name":"chanaka",
"rms_sell":"37",
"orm_repair":"30 ",
"total":"67",
"cash":"17",
"card":"50",
"opening_bal":"10.00 ",
"purchases":"0 ",
"final_total":"27",
"till_total":"60",
"difference":"33",
"nextday_opening_bal":"4",
"created_time":"2013-12-12",
"banking":"51"
},
{
"shop_code":"KF",
"first_name":"chanaka",
"rms_sell":"37",
"orm_repair":"30 ",
"total":"67",
"cash":"17",
"card":"50",
"opening_bal":"10.00 ",
"purchases":"0 ",
"final_total":"27",
"till_total":"60",
"difference":"33",
"nextday_opening_bal":"4",
"created_time":"2013-12-12",
"banking":"51"
}
],
"2013-12-11":[
{
"shop_code":"PC",
"first_name":"chanaka",
"rms_sell":"60",
"orm_repair":"30 ",
"total":"90",
"cash":"40",
"card":"50",
"opening_bal":"10.00 ",
"purchases":"0 ",
"final_total":"50",
"till_total":"60",
"difference":"10",
"nextday_opening_bal":"4",
"created_time":"2013-12-11",
"banking":"51"
},
{
"shop_code":"KF",
"first_name":"chanaka",
"rms_sell":"60",
"orm_repair":"30 ",
"total":"90",
"cash":"40",
"card":"50",
"opening_bal":"10.00 ",
"purchases":"0 ",
"final_total":"50",
"till_total":"60",
"difference":"10",
"nextday_opening_bal":"4",
"created_time":"2013-12-11",
"banking":"51"
}
],
"2013-12-10":[
{
"shop_code":"PC",
"first_name":"chanaka",
"rms_sell":"60",
"orm_repair":"30 ",
"total":"90",
"cash":"40",
"card":"50",
"opening_bal":"10.00 ",
"purchases":"0 ",
"final_total":"50",
"till_total":"60",
"difference":"10",
"nextday_opening_bal":"4",
"created_time":"2013-12-10",
"banking":"51"
},
{
"shop_code":"KF",
"first_name":"chanaka",
"rms_sell":"60",
"orm_repair":"30 ",
"total":"90",
"cash":"40",
"card":"50",
"opening_bal":"10.00 ",
"purchases":"0 ",
"final_total":"50",
"till_total":"60",
"difference":"10",
"nextday_opening_bal":"4",
"created_time":"2013-12-10",
"banking":"51"
}
]
},
"eod_all_data":{
"2013-12-13":{
"shop_code":"PC",
"first_name":"chanaka",
"sum_rms_sell":"74",
"sum_orm_repair":"60",
"total":"134",
"sum_cash":"34",
"sum_card":"100",
"sum_opening_bal":"20",
"sum_purchases":"0",
"final_total":"54",
"sum_till_total":"120",
"difference":"66",
"sum_next_day_bal":"8",
"created_time":"2013-12-13",
"sum_banking":"102"
},
"2013-12-12":{
"shop_code":"KF",
"first_name":"chanaka",
"sum_rms_sell":"74",
"sum_orm_repair":"60",
"total":"134",
"sum_cash":"34",
"sum_card":"100",
"sum_opening_bal":"20",
"sum_purchases":"0",
"final_total":"54",
"sum_till_total":"120",
"difference":"66",
"sum_next_day_bal":"8",
"created_time":"2013-12-12",
"sum_banking":"102"
},
"2013-12-11":{
"shop_code":"PC",
"first_name":"chanaka",
"sum_rms_sell":"120",
"sum_orm_repair":"60",
"total":"180",
"sum_cash":"80",
"sum_card":"100",
"sum_opening_bal":"20",
"sum_purchases":"0",
"final_total":"100",
"sum_till_total":"120",
"difference":"20",
"sum_next_day_bal":"8",
"created_time":"2013-12-11",
"sum_banking":"102"
},
"2013-12-10":{
"shop_code":"KF",
"first_name":"chanaka",
"sum_rms_sell":"120",
"sum_orm_repair":"60",
"total":"180",
"sum_cash":"80",
"sum_card":"100",
"sum_opening_bal":"20",
"sum_purchases":"0",
"final_total":"100",
"sum_till_total":"120",
"difference":"20",
"sum_next_day_bal":"8",
"created_time":"2013-12-10",
"sum_banking":"102"
}
}
}

它有两个主要数组eod_dataeod_all_data

这是我的js

    jQuery.ajax({
        url:base_url+"index.php/eod_report/search_to_date",
        type:"POST",
        data:{from_date:from_date,to_date:to_date},
        datatype:'json',
        success:function(data){

                           console.log(data.eod_data);//returns Undefined

        }

    });

如何通过这个对象,请提前帮助,谢谢。

1 个答案:

答案 0 :(得分:4)

您的代码中的问题是您正在指定

    datatype:'json'

“dataType”区分大小写:将行更改为

    dataType:'json'