如何使用javascript

时间:2018-12-11 12:26:30

标签: javascript

我正在使用ajax从数据库中获取数据。这是我的Json数据

[{
    "0": {
        "from_date": "12-12-2018",
        "time": "09:30AM"
    },
    "Department": {
        "department": "Computer Science & Engg"
    },
    "Section": {
        "section": "B"
    },
    "Staff": {
        "id": "40052",
        "first_name": "Pushpalatha"
    }
}, {
    "0": {
        "from_date": "13-12-2018",
        "time": "10:00AM"
    },
    "Department": {
        "department": "Computer Science & Engg"
    },
    "Section": {
        "section": "C"
    },
    "Staff": {
        "id": "40054",
        "first_name": "Pavan Kumar"
    }
}, {
    "0": {
        "from_date": "14-12-2018",
        "time": "11:00AM"
    },
    "Department": {
        "department": "Computer Science & Engg"
    },
    "Section": {
        "section": "D"
    },
    "Staff": {
        "id": "40066",
        "first_name": "Shobhan"
    }
}, {
    "0": {
        "from_date": "15-12-2018",
        "time": "12:30AM"
    },
    "Department": {
        "department": "Computer Science & Engg"
    },
    "Section": {
        "section": "E"
    },
    "Staff": {
        "id": "40068",
        "first_name": "Duddela Sai Prashanth"
    }
}, {
    "0": {
        "from_date": "17-12-2018",
        "time": "02:30PM"
    },
    "Department": {
        "department": "Computer Science & Engg"
    },
    "Section": {
        "section": "F-CHE"
    },
    "Staff": {
        "id": "40072",
        "first_name": "Sunil"
    }
}]

我正在使用javascript将值附加到表中。代码如下。

 html += "<tr><td>"+element.Department.department +"</td><td>"+
         element.Section.section+"</td><td>"+element.Staff.id+"</td><td>"+
         element.Staff.first_name+"</td><td>"+element.0.from_date +"</td><td>"+
         element.0.time+"</td></tr>";

如果我将“ 0”和“ from_date”和“ time”一起使用(例如element.0.from_dateelement.0.time),则不会附加值到桌子上。当我删除0时,将重新添加Remqaining值。请帮助我解决问题。

0 个答案:

没有答案