我希望使用以下for循环
将每个员工的详细信息输入到表中这是我的代码:
var JSONObject =jsonString;
var i =0;
for (var key in JSONObject) {
if (JSONObject.hasOwnProperty(key)) {
console.log(JSONObject[i]);
i++;
}
}
这是我的对象在执行下面的代码之后:
Object { EMP_ID: "12171", DATE: "2017-12-10", PROCESSED_TIME: "2017-12-22 09:56:24", PREVIOUS_IN: "2017-12-10 07:45:33",
PREVIOUS_OUT: "2017-12-10 17:00:46", DESCRIPTION: "Sunday attendance deduction",
IN_AFTER_PROCESS: null,
OUT_AFTER_PROCESS: null, TIME_GAP_AFTER_PROCESS: null, TIME_GAP_BEFORE_PROCESS: "-09:15:13", … }
答案 0 :(得分:0)
试试这个
var me = {EMP_ID: "12171", DATE: "2017-12-10", PROCESSED_TIME: "2017-12-22 09:56:24", PREVIOUS_IN: "2017-12-10 07:45:33",
PREVIOUS_OUT: "2017-12-10 17:00:46", DESCRIPTION: "Sunday attendance deduction",
IN_AFTER_PROCESS: null,
OUT_AFTER_PROCESS: null, TIME_GAP_AFTER_PROCESS: null}
//Now, loop through your object and alert every value. *Tyler --> 24 --> 6'0 --> Male, etc etc
for (var key in me) {
if (me.hasOwnProperty(key)){
console.log(me[key]);
}
}

答案 1 :(得分:0)
使用我的JSON找到的解决方案没有办法做到这一点 只需从php
设置html输出echo "<tr><td> {$emp_id}</td><td>{$description} </td> </tr>";
像这样设置ajax响应
$("#id_of_table tbody").html(response);