次のコード/データを使用して、各ハウスで最も収益の高い学生のリストを表示しています。
データ
添付資料1:User_Infoはオブジェクトの配列です
添付ファイル2:User_Infoは、このようなオブジェクトの配列です
添付資料3:Database_Infoはこのようなオブジェクトです
コード
HPAnalysisObject.dispHPTotals = function(User_Info, Database_Info) {
// See attachments 1 and 2
console.log(User_Info);
// See attachment 3
console.log(Database_Info);
// "label" is just a text title, like "Eagles"
var html = '<h2>' + HPAnalysisObject.label + '</h2>' +
// "TotalPoints" is an integer figure
'<div id="total">' + Database_Info.TotalPoints + '</div>';
// create the table to display
html += '<table><tr><th class="name">Name</th><th class="points">Points</th></tr>';
// use "for, in" to access the value of the object key (which is the user's ID)
for (var id in Database_Info.UserDetails) {
html += '<tr>';
for (var i = 0; i < User_Info.length; i++) {
if (User_Info[i].id == id) {
// if the User_Info and Database_Info objects match up on the User's ID, add table cells to our html variable
html += '<td class="name">' + User_Info[i].firstname + ' ' + User_Info[i].surname + '</td><td class="points">' + Database_Info.UserDetails[id] + '</td>';
}
}
html += '</tr>';
}
html += '</table>';
$('div#display').html(html);
};
問題
奇妙なことに、Firefoxでは、生徒は私のPHPスクリプトから受信されるため、これらの生徒は正しい番号順に表示されます。
ただし、GoogleChromeとInternetExplorerでは、一見ランダムな順序で表示されます。
私の最初の考えはオブジェクトを注文することでしたが、ここでいくつかの質問を読んだので、オブジェクトの注文はベストプラクティスではないようです。
このコードを書き直して、すべてのブラウザで同じ表形式のデータを正しい順序で表示できるようにすることはできますか?
前もって感謝します、