Output php data into jquery array?

前端 未结 2 1041
礼貌的吻别
礼貌的吻别 2021-01-28 19:22

I\'m creating a timeline using timesheet.js. The data will be input via custom fields in Wordpress. I want to be able to output that php data into the jquery array. Is that poss

2条回答
  •  时光说笑
    2021-01-28 19:35

    It's quite simple to do this, really: just construct the array in php, and echo its json_encoded value:

     var theArray = '.json_encode($array).';';
    } ?>
    

    Job done, you now have a JS variable called theArray, and its value will be an array of arrays, containing all of the data you need to create new Timesheet('timesheet', 2002, 2013, theArray);

提交回复
热议问题