{
"data": [
{
"date": "2013-03-07",
"id": "2",
"vt_color": "#548dd4",
"vt_name": "follow up",
"duration": "20",
"time_booked": "12:00:00",
"stats": "booked",
"doctor_id": "00002",
"patient_id": "00003"
},
{
"date": "2013-03-08",
"id": "3",
"vt_color": "#76923c",
"vt_name": "ultrasound",
"duration": "30",
"time_booked": "08:00:00",
"stats": "booked",
"pt_name": "demo patien",
"dr_name": "Momen Alzalabany",
"doctor_id": "00002",
"patient_id": "00009"
}
]
}
我想要的是从中创建另一个数组,包括 vt_name、vt_color 和数据索引,所以我使用 jquery
var words = [];
$.each(arr['data'],function(ref){
words[this.doctor_id].push({name: this.vt_color,color: this.vt_name,index:ref});
});
console.log(koko);
FAIL : words[this.do_id] 未定义....
我怎样才能做到这一点 ?我希望结果是
抱歉,我是 json/js 的新手
我希望 php 的结果是
['00002'=>[
['name'=>'follow up','color'=>'#548dd4',index=>[0,3,4]],
['name'=>'ultrasound','color'=>'#769dd4',index=>[1,5,8]]
]
]