私はスチューデントオブジェクトを私の配列に追加する方法を知りました。一度それを修正したら、配列の中にあるものをテーブルにhtmlファイルで表示しようとしました。配列からテーブルにオブジェクトを追加する
学生オブジェクト:
var Student = function (fullName, email, phone, category, groupID) {
this.fullName = fullName;
this.email = email;
this.phone = phone;
this.category = category;
this.groupID = groupID;
};
studentArray:
var studentArray = new Array(Student);
makeTable機能:
function makeTable() {
var student1 = new Student("Waw","waaw","awaw","waaw","waaw");
studentArray.push(student1);
document.write("<table>");
document.write("<thead><tr><th>Full Name</th><th>Email</th><th>Phone</th><th>Category</th><th>Group</th></tr></thead>");
document.write("<tbody>");
for(i = 0; i < studentArray.length; i++){
document.write("<tr><td>" + studentArray[i].fullName +"</td><td>" + studentArray[i].email +"</td><td>" + studentArray[i].phone +"</td><td>" + studentArray[i].category +"</td><td>" + studentArray[i].groupID +"</td></tr>");
}
document.write("</tbody>");
document.write("</table>");
}
HTMLファイル:
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="../script/scripts.js" type="text/javascript"></script>
</head>
<body>
<script>
makeTable();
</script>
</body>
</html>
出力:
http://i.imgur.com/K9UWIyx.png
私は配列を作ったかのように私はJavaでregularyプログラムが正常に、しかし、私はこれが機能していない想像できる唯一の理由は、ありますStudentArrayにstudent1を挿入した後も、配列が空です。
ありがとうございます。
このフィドルと
var studentArray = new Array(Student);
が働いて、それを示して置き換えますあなたの 'Student'関数と等しい要素を持つ配列を開始するので、' undefined'値を返します。あなたのコードにテーブルに値が設定されない原因となっている何か他のものがあります。 –