Mẫu khai báo và tra cứu dữ liệu danh mục trò chơi cục bộ bằng JavaScript và JSON.
{ } gameCatalog.js{ } gameCatalog.json
Sao chép mã
JavaScript
// Cấu hình tham số cục bộ cho danh mục trò chơi cwin
const localGameCatalog = [
{ id: "150" , name: "Gemstones Gold" , category: "Nổ hũ / Slot" },
{ id: "153" , name: "Pinata Wins" , category: "Nổ hũ / Slot" },
{ id: "138" , name: "Cruise Royale" , category: "Nổ hũ / Slot" }
];
function getGameInfo(gameId) {
return localGameCatalog.find(item => item.id === gameId) || null ;
}
// Ví dụ kiểm tra thông tin cục bộ
const selectedGame = getGameInfo("150" );
console.log("Trò chơi đã chọn:" , selectedGame); JSON
{
"platform" : "cwin" ,
"catalog" : [
{
"id" : "150" ,
"name" : "Gemstones Gold" ,
"category" : "Nổ hũ / Slot"
},
{
"id" : "153" ,
"name" : "Pinata Wins" ,
"category" : "Nổ hũ / Slot"
},
{
"id" : "138" ,
"name" : "Cruise Royale" ,
"category" : "Nổ hũ / Slot"
}
]
}